#include <fstream>
#include <vector>

using namespace std;

vector<vector<int>> g;
vector<int> p;
vector<int> depth;
vector<vector<int>> marks;
vector<vector<int>> common;

void dfs(int u, int dep) {
  depth[u] = dep;
  for (vector<int>::iterator v = g[u].begin(); v != g[u].end(); v++) {
    dfs(*v, dep + 1);
  }
}

int lca(int a, int b, int k) {
  if (a == b) return a;
  if (depth[a] < depth[b]) {
    marks[b].push_back(k);
    return lca(a, p[b], k);
  } else {
    marks[a].push_back(k);
    return lca(p[a], b, k);
  }
}

int main() {
  ifstream cin("twopaths.in");
  ofstream cout("twopaths.out");
  int n, k, a, b;
  cin >> n >> k;
  p = vector<int>(n, 0);
  depth = vector<int>(n, 0);
  g = vector<vector<int>>(n, vector<int>());
  marks = vector<vector<int>>(n, vector<int>());
  common = vector<vector<int>>(k, vector<int>(k, 0));
  for (int i = 1; i < n; i++) {
    cin >> p[i];
    p[i]--;
    g[p[i]].push_back(i);
  }
  dfs(0, 0);
  for (int i = 0; i < k; i++) {
    cin >> a >> b;
    a--;
    b--;
    lca(a, b, i);
  }
  for (int i = 1; i < n; i++) {
    for (vector<int>::iterator c1 = marks[i].begin(); c1 != marks[i].end(); c1++) {
      for (vector<int>::iterator c2 = c1 + 1; c2 != marks[i].end(); c2++) {
        common[*c1][*c2]++;
        common[*c2][*c1]++;
      }
    }
  }
  int ans = 0, c1 = 0, c2 = 1;
  for (int i = 0; i < k; i++) {
    for (int j = i + 1; j < k; j++) {
      if (common[i][j] > ans) {
        ans = common[i][j];
        c1 = i;
        c2 = j;
      }
    }
  }
  cout << ans << endl << c1 + 1<< " " << c2 + 1 << endl;
  return 0;
}
