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

public class Twopaths {

    private int log;
    private HashSet<Integer>[] graph;
    private int[] level, tin, tout;
    private int[][] up;

    private void solve() throws IOException {
        int n = nextInt(), k = nextInt();
        graph = new HashSet[n];
        for (int i = 0; i < n; i++) {
            graph[i] = new HashSet<>();
        }

        int[] prev = new int[n];
        prev[0] = 0;
        for (int i = 1; i < n; i++) {
            prev[i] = nextInt() - 1;
            graph[prev[i]].add(i);
        }

        level = new int[n];
        tin = new int[n];
        tout = new int[n];
        dfs(0, 0);
        log = log2(n);
        up = new int[n][log];
        for (int bit = 0; bit < log; bit++) {
            for (int i = 0; i < n; i++) {
                if (bit == 0) {
                    up[i][0] = prev[i];
                } else {
                    up[i][bit] = up[up[i][bit - 1]][bit - 1];
                }
            }
        }

        Pair[] couriers = new Pair[k];
        for (int i = 0; i < k; i++) {
            couriers[i] = new Pair(nextInt() - 1, nextInt() - 1);
        }

        int result = 0, p = 0, q = 1;
        for (int i = 1; i < k; i++) {
            for (int j = 0; j < i; j++) {
                int a = couriers[i].first, b = couriers[i].second,
                        c = couriers[j].first, d = couriers[j].second;
                int v = lca(a, b), u = lca(c, d);
                if (v == u) {
                    int x = lca(a, c), y = lca(a, d), z = lca(b, c), t = lca(b, d);
                    int r = level[x] + level[y] + level[z] + level[t] - 4 * level[v];
                    System.out.println(j + " " + i + " " + r);
                    if (r > result) {
                        result = r;
                        p = j;
                        q = i;
                    }
                } else if (isAncestor(v, u)) {
                    int x = lca(a, u), y = lca(b, u);
                    if (x != v && level[a] > level[u]) {
                        int z = lca(a, c), t = lca(a, d);
                        int r = level[z] + level[t] - 2 * level[u];
                        System.out.println(j + " " + i + " " + r);
                        if (r > result) {
                            result = r;
                            p = j;
                            q = i;
                        }
                    } else if (y != v && level[b] > level[u]) {
                        int z = lca(b, c), t = lca(b, d);
                        int r = level[z] + level[t] - 2 * level[u];
                        System.out.println(j + " " + i + " " + r);
                        if (r > result) {
                            result = r;
                            p = j;
                            q = i;
                        }
                    }
                } else if (isAncestor(u, v)) {
                    int x = lca(c, v), y = lca(d, v);
                    if (x != u && level[c] > level[v]) {
                        int z = lca(c, a), t = lca(c, b);
                        int r = level[z] + level[t] - 2 * level[v];
                        System.out.println(j + " " + i + " " + r);
                        if (r > result) {
                            result = r;
                            p = j;
                            q = i;
                        }
                    } else if (y != u && level[d] > level[v]) {
                        int z = lca(d, a), t = lca(d, b);
                        int r = level[z] + level[t] - 2 * level[v];
                        System.out.println(j + " " + i + " " + r);
                        if (r > result) {
                            result = r;
                            p = j;
                            q = i;
                        }
                    }
                } else {
                    System.out.println(j + " " + i + " " + 0);
                }
            }
        }

        out.println(result);
        out.println((p + 1) + " " + (q + 1));
    }

    private class Pair {
        int first, second;

        public Pair(int first, int second) {
            this.first = first;
            this.second = second;
        }
    }

    private int lift(int v, int level) {
        for (int bit = 0; bit < log; bit++) {
            if (((level >> bit) & 1) > 0) {
                v = up[v][bit];
            }
        }
        return v;
    }

    private int lca(int v, int u) {
        int bit = log - 1;
        while (!isAncestor(v, u)) {
            while (bit > 0 && isAncestor(up[v][bit], u)) {
                bit--;
            }
            v = up[v][bit];
        }

        return v;
    }

    private boolean isAncestor(int v, int u) {
        return tin[v] <= tin[u] && tout[v] >= tout[u];
    }

    private int log2(int n) {
        return 32 - Integer.numberOfLeadingZeros(n);
    }

    private int t = 0;

    private void dfs(int v, int lev) {
        level[v] = lev;
        tin[v] = t;
        t++;

        for (int u : graph[v]) {
            dfs(u, lev + 1);
        }

        tout[v] = t;
        t++;
    }

    private void run() {
        try {
            String fileName = "twopaths";
            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 Twopaths().run();
    }

}