#include <stdio.h>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
#define ll long long int;
using namespace std;
const int mod=1e9+7;

int p[222222],aa[222222],bb[222222],d[222222],pr[222222][25];
vector<int> v[222222];

void dfs(int x){
	int i,t;
	for(i=0;i<v[x].size();i++){
		t=v[x][i];
		d[t]=d[x]+1;
		dfs(t);
	}
}

int lca(int x,int y){
	int i,j;
	if(d[x]>d[y]){
		swap(x,y);
	}
	if(d[x]<d[y]){
		for(i=24;i>=0;i--){
			if(pr[y][i]>=0&&d[pr[y][i]]>=d[x]){
				y=pr[y][i];
			}
		}
	}
	if(x==y){
		return x;
	}
	for(i=24;i>=0;i--){
		if(pr[x][i]>=0&&pr[x][i]!=pr[y][i]){
			x=pr[x][i];
			y=pr[y][i];
		}
	}
	return p[x];
}

int main(){
#pragma warning(disable:4996)
#pragma comment(linker,"/STACK:536870912")
#ifdef _DEBUG
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
#else
	freopen("twopaths.in","rt",stdin);
	freopen("twopaths.out","wt",stdout);
#endif
	int n,k,i,j,a,b,c,x,y,z,m,mi1,mi2,s,l,e;
	scanf("%d%d",&n,&k);
	p[0]=-1;
	for(i=1;i<n;i++){
		scanf("%d",&p[i]);
		p[i]--;
		v[p[i]].push_back(i);
	}
	d[0]=0;
	dfs(0);
	for(i=0;i<n;i++){
		for(j=0;j<25;j++){
			pr[i][j]=-1;
		}
	}
	for(i=1;i<n;i++){
		pr[i][0]=p[i];
		j=1;
		for(j=1;j<25;j++){
			if(pr[pr[i][j-1]][j-1]>=0){
				pr[i][j]=pr[pr[i][j-1]][j-1];
			} else{
				break;
			}
		}
	}
	for(i=0;i<k;i++){
		scanf("%d%d",&aa[i],&bb[i]);
		aa[i]--;
		bb[i]--;
	}
	m=-1;
	for(i=0;i<k-1;i++){
		for(j=i+1;j<k;j++){
			a=aa[i];
			b=bb[i];
			x=aa[j];
			y=bb[j];
			c=lca(a,b);
			z=lca(x,y);
			s=0;
			if(c==z){
				s=-(d[c]-d[lca(a,x)]+d[c]-d[lca(b,y)]);
				s=max(s,-(d[c]-d[lca(a,y)]+d[c]-d[lca(b,x)]));
			} else{
				e=lca(c,z);
				if(e==c){
					if(lca(a,x)==z){
						s=d[lca(y,a)]-d[z];
					}
					if(lca(b,x)==z){
						s=d[lca(y,b)]-d[z];
					}
					if(lca(a,y)==z){
						s=d[lca(x,a)]-d[z];
					}
					if(lca(b,y)==z){
						s=d[lca(x,b)]-d[z];
					}
				}
				if(e==z){
					if(lca(a,x)==c){
						s=d[lca(b,x)]-d[c];
					}
					if(lca(y,a)==c){
						s=d[lca(b,y)]-d[c];
					}
					if(lca(x,b)==c){
						s=d[lca(a,x)]-d[c];
					}
					if(lca(b,y)==c){
						s=d[lca(a,y)]-d[c];
					}
				}
			}
			if(s>m){
				m=s;
				mi1=i;
				mi2=j;
			}
		}
	}
	printf("%d\n%d %d",m,mi1+1,mi2+1);

	return 0;
}