#include<bits/stdc++.h>

using namespace std;

typedef long long lint;

#define X first
#define Y second
#define F(i, l, r) for(auto i = l; i != r; i++)
#define Df(i, l, r) for(auto i = l; i != r; i--)
#define rs resize
#define asg assign
#define mk make_pair
#define ins insert
#define era erase
#define all(x) x.begin(),x.end()
#define ret return
#define cont continue
#define brk break

const string fname = "twopaths";

struct node{
    node *l, *r;
    int v;
};

int n, k;
vector<list<int> > gr;
vector<int> dfs_list;
vector<int> first;
vector<int> h;
node * root;
vector<pair<int, int> > cour;

void dfs(int v, int p = -1){
    h[v] = (p == -1) ? 0 : (h[p] + 1);
    dfs_list.push_back(v);
    F(it, gr[v].begin(), gr[v].end()){
        int u = *it;
        if(u == p)
            cont;
        dfs(u, v);
        dfs_list.push_back(v);
    }
}

node* build(int l, int r){
    node * nnode = new node;
    if(l == r){
        nnode->v = dfs_list[l];
        ret nnode;
    }
    int mid = (l + r) >> 1;
    nnode->l = build(l, mid);
    nnode->r = build(mid + 1, r);
    if(h[nnode->l->v] < h[nnode->r->v])
        nnode->v = nnode->l->v;
    else
        nnode->v = nnode->r->v;
    ret nnode;
}

int get(node * v, int l, int r, int ul, int ur){
    if(ul > ur)
        ret -1;
    if(l == ul && ur == r)
        ret v->v;
    int mid = (l + r) >> 1;
    int vl = get(v->l, l, mid, ul, min(ur, mid));
    int vr = get(v->r, mid + 1, r, max(ul, mid + 1), ur);
    if(vl == -1)
        ret vr;
    if(vr == -1)
        ret vl;
    if(h[vl] < h[vr])
        ret vl;
    else
        ret vr;
}

void prepare(){
    F(i, 0, (int)dfs_list.size()){
        int v = dfs_list[i];
        if(first[v] == -1)
            first[v] = i;
    }
    root = build(0, (int)dfs_list.size() - 1);
}

int lca(int u, int v){
    if(first[v] > first[u])
        swap(v, u);
    ret get(root, 0, (int)dfs_list.size() - 1, first[v], first[u]);
}

int dist(int v, int u){
    int lc = lca(v, u);
    ret h[v] + h[u] - 2 * h[lc];
}

int ssl(pair<int, int> p1, pair<int, int> p2){
    int lb = lca(p1.X, p2.X);
    int le = lca(p1.Y, p2.Y);
    ret dist(lb, le);
}

int solve(int c1, int c2){
    int res = ssl(cour[c1], cour[c2]);
    swap(cour[c1].X, cour[c1].Y);
    res = max(res, ssl(cour[c1], cour[c2]));
    swap(cour[c2].X, cour[c2].Y);
    res = max(res, ssl(cour[c1], cour[c2]));
    swap(cour[c1].X, cour[c1].Y);
    res = max(res, ssl(cour[c1], cour[c2]));
    swap(cour[c2].X, cour[c2].Y);
    ret res;
}

int maxd = 0;
int a1 = 0, a2 = 1;

int main(){
    string fin = fname + ".in";
    string fout = fname + ".out";
    freopen(fin.c_str(), "r", stdin);
    freopen(fout.c_str(), "w", stdout);
    scanf("%d%d", &n, &k);
    gr.rs(n); first.rs(n); h.rs(n); first.asg(n, -1);
    F(i, 1, n){
        int j;
        scanf("%d", &j);
        j--;
        gr[i].push_back(j); gr[j].push_back(i);
    }
    cour.rs(k);
    F(i, 0, k){
        int v, u;
        scanf("%d%d", &v, &u);
        v--; u--;
        cour[i] = mk(v, u);
    }
    dfs(0);
    prepare();
    F(i, 0, k){
        F(j, i + 1, k){
            int curr = solve(i, j);
            if(curr > maxd){
                maxd = curr;
                a1 = i; a2 = j;
            }
        }
    }
    printf("%d\n%d %d", maxd, a1 + 1, a2 + 1);
    ret 0;
}
