import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.StringTokenizer;

public class C {
	static int n, k;
	static int[][] pairs;

	public static void read() throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("twopaths.in"));
		StringTokenizer st = new StringTokenizer(in.readLine());
		n = Integer.parseInt(st.nextToken());
		k = Integer.parseInt(st.nextToken());
		int[] ancs = new int[n - 1];
		st = new StringTokenizer(in.readLine());
		for (int i = 0; i < n - 1; i++) {
			ancs[i] = Integer.parseInt(st.nextToken()) - 1;
		}
		Node.init(n, ancs);
		Node.nodes[0].dfs();
		pairs = new int[k][2];
		for (int i = 0; i < k; i++) {
			st = new StringTokenizer(in.readLine());
			pairs[i][0] = Integer.parseInt(st.nextToken()) - 1;
			pairs[i][1] = Integer.parseInt(st.nextToken()) - 1;
		}
		in.close();
	}

	public static void main(String[] args) throws IOException {
		read();
		int max = -1;
		int maxI = 0, maxJ = 0;
		for (int i = 0; i < pairs.length; i++) {
			int[] pair1 = pairs[i];
			ArrayList<Node> path1 = Node.getPath(Node.nodes[pair1[0]], Node.nodes[pair1[1]]);
			for (int j = i + 1; j < pairs.length; j++) {
				int[] pair2 = pairs[j];
				ArrayList<Node> path2 = Node.getPath(Node.nodes[pair2[0]], Node.nodes[pair2[1]]);
				//System.out.println(path1);
				//System.out.println(path2);
				HashSet<Node> set = new HashSet<>();
				set.addAll(path1);
				int cnt = 0;
				for (Node node : path2)
					if (set.contains(node))
						cnt++;
				if (max < cnt) {
					max = cnt;
					maxI = i;
					maxJ = j;
				}
			}
		}
		PrintWriter out = new PrintWriter("twopaths.out");
		if (max != 0)
			max--;
		out.println(max);
		out.println((maxI + 1) + " " + (maxJ + 1));
		out.close();
	}

}

class Node {
	static int n;
	int num;
	static Node[] nodes;
	int h;
	int timeIn;
	int timeOut;
	ArrayList<Node> ancs = new ArrayList<>();
	ArrayList<Node> children = new ArrayList<>();

	public static void init(int n, int[] ancs) {
		Node.n = n;
		nodes = new Node[n];
		for (int i = 0; i < n; i++) {
			nodes[i] = new Node();
			nodes[i].num = i + 1;
		}
		for (int i = 1; i < n; i++) {
			nodes[i].ancs.add(nodes[ancs[i - 1]]);
			nodes[ancs[i - 1]].children.add(nodes[i]);
		}
	}

	static int time = 0;

	public void dfs() {
		if (ancs.size() != 0)
			h = ancs.get(0).h + 1;
		timeIn = ++time;
		for (Node ch : children) {
			ch.dfs();
		}
		timeOut = ++time;
	}

	void calcAncs() {
		h = ancs.get(0).h + 1;
		for (Node ch : children) {
			ch.calcAncs();
		}
		if (children.size() == 0) {
			Node tmp = ancs.get(0);
			int sh = 1;
			while (tmp.h != 0) {
				for (int i = 0; i < sh && tmp.h != 0; i++) {
					tmp = tmp.ancs.get(0);
				}
				ancs.add(tmp);
				sh <<= 1;
			}
		}
	}

	public static ArrayList<Node> getPath(Node a, Node b) {
		ArrayList<Node> path = new ArrayList<>();
		path.add(a);
		while (!a.isAnc(b) && a.h != 0) {
			a = a.ancs.get(0);
			path.add(a);
		}
		ArrayList<Node> tmp = new ArrayList<>();
		while (b != a) {
			tmp.add(b);
			if (b.h == 0)
				break;
			b = b.ancs.get(0);
		}
		Collections.reverse(tmp);
		path.addAll(tmp);
		return path;
	}

	boolean isAnc(Node node) {
		return timeIn < node.timeIn && timeOut > node.timeOut;
	}

	@Override
	public String toString() {
		return num + "";
	}
}