#pragma comment(linker, "/Stack:512000000")
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long LL;
typedef double dbl;

const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const dbl EPS = 1e-9;

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#elif 1
# define PROB "twopaths"
  freopen(PROB".in", "r", stdin);
  freopen(PROB".out", "w", stdout);
#endif
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, k;
  cin >> n >> k;

  const int MAXN = 4096;

  vector<int> g(n + 1);
  vector<int> depth(n + 1);
  g[0] = 0;
  g[1] = 1;

  depth[1] = 1;

  for (int i = 2; i <= n; ++i) {
    int a;
    cin >> a;

    g[i] = a;
    depth[i] = depth[a] + 1;
  }

  vector<pair<int, int>> a(k);
  vector<bitset<MAXN>> d(k);
  for (int i = 0; i < k; ++i) {
    int f, t;
    cin >> f >> t;
    a[i] = { f, t };

    d[i][f] = d[i][t] = 1;

    while (depth[f] > depth[t]) {
      d[i][f] = 1;
      f = g[f];
    }
    swap(f, t);
    while (depth[f] > depth[t]) {
      d[i][f] = 1;
      f = g[f];
    }

    while (f != t) {
      f = g[f];
      t = g[t];
      d[i][f] = d[i][t] = 1;
    }
  }

  int ans = 0, id1 = 0, id2 = 1;

  for (int i = 0; i < k; ++i) {
    for (int j = i + 1; j < k; ++j) {
      auto tmp = d[i];
      tmp &= d[j];
      int bc = tmp.count();

      if (bc > ans) {
        ans = bc;
        id1 = i;
        id2 = j;
      }
    }
  }

  cout << ans << '\n' << id1 + 1 << ' ' << id2 + 1 << '\n';

  return 0;
}