#include <bits/stdc++.h>
using namespace std;
#define DB(v) cerr << #v << ' ' << v << endl
#define sz(v) int(v.size())

typedef pair <int,int> pii;

int n, k;

const int N = 1e5 + 9;

vector <int> graph [N];
vector <pii> cureer;
vector <int> parent;

void prepare() {
    cin >> n >> k;
    int x;
    for(int i = 2;i <= n; ++i) {
        cin >> x;
        graph[x].push_back(i);
        graph[i].push_back(x);
    }
    int a, b;
    for(int i = 1;i <= k; ++i) {
        cin >> a >> b;
        cureer.push_back(make_pair(a, b));
    }
}

void dfs(int v, int fin, int p = -1) {
    parent[v] = p;
    if(v == fin) return;
    for(int to: graph[v]) {
        if(to == p) continue;
        dfs(to, fin, v);
    }
}

set <pii> current;

int go(int x, bool need) {
    int res = 0;
    while(parent[x] != -1) {
        pii cur = make_pair(min(x, parent[x]), max(x, parent[x]));
        if(current.find(cur) != current.end()) res++;
        else if(need)
            current.insert(cur);
        x = parent[x];
    }
    return res;
}

int main()
{
#ifdef HOME
    freopen("input.txt","r",stdin);
#else
    freopen("twopaths.in","r",stdin);
    freopen("twopaths.out","w",stdout);
#endif
    ios::sync_with_stdio(NULL); cin.tie(NULL);
    prepare();
    int ans = 0, one = -1, two = -1;
    for(int i = 0;i < k; ++i) {
        current.clear();
        int a = cureer[i].first, b = cureer[i].second;
        parent.assign(n + 1, -1);
        dfs(a, b);
        go(b, true);
        for(int j = i + 1; j < k; ++j) {
            parent.assign(n + 1, -1);
            a = cureer[j].first, b = cureer[j].second;
            dfs(a, b);
            int cur = go(b, false);
            if(cur >= ans) {
                ans = cur;
                one = i + 1, two = j + 1;
            }
        }
    }
    cout << ans << endl;
    cout << one << ' ' << two;
    return 0;
}
