import java.io.*;
import java.util.*;

public class mian {
	String fileName = "twopaths";

	void dfs(int v, int p, int d) {
		tin[v] = time;
		time++;
		dist[v] = d;
//		System.out.println(v+  " " + p);
		for(int i = 0; i < g[v].size(); i++){
			dfs(g[v].get(i), v, d + 1);
		}
		time++;
		tout[v] = time;
	}

	int n;
	int k;
	ArrayList<Integer> g[];
	int[] tin, tout;
	int time;
	int[][] edge;
	int[][] st;
	int[] par;
	boolean par(int a, int b){
		if (tin[a] <= tin[b] && tout[a] >= tout[b])
			return true;
		return false;
	}
	int lca(int a, int b){
		if (par(a, b)){
			return a;
		}
		if (par(b, a)){
			return b;
		}
//		int c = Math.min(a, b);
//		int k = Math.max(a, b);
//		a = c;
//		b = k;
		int i = 10;
		while (! par(st[a][1], b)){
//			System.out.println(a + " " + b);
			if (! par(st[a][i], b)){
				a = st[a][i];
			}
			i = Math.max(i - 1, 1);
		}
		return st[a][1];
	}
	int[] dist;
	int path(int a, int r_a, int b, int r_b){
		int res = 0;
		int u = lca(a, b);
		int w = lca(r_a, r_b);
//		System.out.println(u + " " + w + " " + a + " " + r_a + " " + r_b + " "+ b);
		if (par(r_a, r_b)){
			return Math.max(0, dist[u] - dist[r_b]);
		}else if (par(r_b, r_a)){
			return Math.max(0, dist[u] - dist[r_a]);
		}
		return 0;
	}
	public void solve() throws IOException {
		int n = nextInt();
		int k = nextInt();
		edge = new int[n][n];
		g = new ArrayList[n];
		st = new int[n + 1][20];
		dist = new int[n];
		for (int i = 0; i < g.length; i++) {
			g[i] = new ArrayList<Integer>();
		}
		st[0][0] = 0;
		for (int i = 0; i < st.length - 1; i++) {
			st[i + 1][0] = i + 1;
		}
		st[0][1] = 1;
		for (int i = 0; i < n - 1; i++) {
			int t = nextInt() - 1;
			g[t].add(i + 1);
			st[i + 1][1] = t;
		}
		for (int k1 = 2; k1 < 20; k1++){
			for(int i = 1; i <= n; i++){
				st[i][k1] = st[st[i][k1 - 1]][k1 - 1];
			}
		}
		tin = new int[n];
		tout = new int[n];
		time = 0;
		dfs(0, -1, 0);
		int[][] p = new int[k][2];
		for (int i = 0; i < p.length; i++) {
			p[i][0] = nextInt() - 1;
			p[i][1] = nextInt() - 1;
		}
		int maxx = -1;
		int ind_a = 0;
		int ind_r = 0;
		for (int i = 0; i < k; i++){
			for(int j = i + 1; j < k; j++){
				int a1 = p[i][0];
				int b1 = p[i][1];
				int u = lca(a1, b1);
				
				int a2 = p[j][0];
				int b2 = p[j][1];
				int w = lca(a2, b2);
				int res = path(a1, u, a2, w); 
//				out.println(res);
				res += path(b1, u, a2, w);
//				System.out.println("--- " + path(b1, u, a2, w));
				res += path(a1, u, b2, w);
//				out.println(res);
				res += path(b1, u, b2, w);
//				out.println(res);
//				System.out.println(a1 + " " + b1 + " " + a2 + " " + b2 + " " + u + " " + w);
				if (res > maxx){
					ind_a = i;
					ind_r = j;
					maxx = res;
				}
			}
		}
		out.println(maxx);
		out.println((ind_a + 1) + " " + (ind_r + 1));
	}

	public void run() {
		try {
			br = new BufferedReader(new FileReader(fileName + ".in"));
			out = new PrintWriter(fileName + ".out");

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public static void main(String[] args) throws IOException {
		Locale.setDefault(Locale.US);
		new mian().run();
	}

}