import java.io.*;
import java.util.BitSet;
import java.util.HashSet;
import java.util.StringTokenizer;

/**
 * Created by roi on 07.04.2016.
 */
public class Task7 {

    void solve(IOReader io) {
        n = io.nextInt();
        k = io.nextInt();
        vxs = new HashSet[k];
        for (int i = 0; i < k; i++) {
            vxs[i] = new HashSet<>();
        }
        parent = new int[n];
        parent[0] = -1;
        child = new HashSet[n];
        for (int i = 0; i < n; i++) {
            child[i] = new HashSet<>();
            child[i].add(i);
        }
        for (int i = 1; i < n; i++) {
            parent[i] = io.nextInt() - 1;
        }
        a = new int[n];
        b = new int[n];
        for (int i = 0; i < k; i++) {
            a[i] = io.nextInt() - 1;
            b[i] = io.nextInt() - 1;
        }

        for (int i = 0; i < n; i++) {
            fillChild(i, -1);
        }

        for (int i = 0; i < k; i++) {
            go(a[i], b[i], i);
            go(b[i], a[i], i);
        }

        int ans = 0;
        int ansI = 0;
        int ansJ = 1;

        for (int i = 0; i < k; i++) {
            for (int j = i + 1; j < k; j++) {

                HashSet<Integer> common = new HashSet<>(vxs[i]);
                common.retainAll(vxs[j]);
                int res = common.size() - 1;

                if (res > ans) {
                    ans = res;
                    ansI = i;
                    ansJ = j;
                }

            }
        }

        io.println(ans);
        io.println((ansI + 1) + " " + (ansJ + 1));
    }

    int n, k;
    int[] parent;
    HashSet<Integer>[] child;
    int[] a, b;
    HashSet<Integer>[] vxs;

    void go(int v, int v2, int idx) {
        vxs[idx].add(v);
        if (!child[v].contains(v2)) {
            go(parent[v], v2, idx);
        }
    }

//    int commonAncestor(int v, int v2) {
//        if (child[v].contains(v2)) {
//            return v;
//        } else if (child[v2].contains(v)) {
//            return v2;
//        } else {
//            return commonAncestor(parent[v], v2);
//        }
//    }

    void fillChild(int v, int from) {
        if (v == -1) return;

        if (from != -1) {
            child[v].addAll(child[from]);
        }
        fillChild(parent[v], v);
    }


    public static void main(String[] args) {
        Task7 solver = new Task7();
        IOReader io = new IOReader("twopaths");
        solver.solve(io);
        io.out.close();
    }

    static class IOReader {
        BufferedReader in;
        StringTokenizer tok;
        PrintWriter out;

        IOReader(String file) {
            try {
                in = new BufferedReader(new FileReader(file + ".in"));
                out = new PrintWriter(file + ".out");
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        String nextToken() {
            if (tok == null || !tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                    return null;
                }
            }
            return tok.nextToken();
        }

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

        int[] readIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

        String readLine() {
            try {
                return in.readLine();
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }

        void println(long x) {
            out.println(x);
        }

        void println(String s) {
            out.println(s);
        }
    }

}