/**
 * Created by roi on 07.04.2016.
 */
import java.io.*;
import java.util.*;

public class C {
    String fileName = "twopaths";
    int[] depth;
    int timer;
    int[] tin;
    int[][] pred;
    ArrayList<Integer>[] pot;
    void dfs(int v, int dep){
        depth[v] = dep;
        tin[v] = timer;
        timer++;
        for (int i1 = 0; i1 < pot[v].size(); i1++){
            dfs(pot[v].get(i1), dep + 1);
        }
    }
    int lca(int a, int b){
        int a1 = a;
        int b1 = b;
        if (a1 == b1){
            return a1;
        }
        if (depth[b] > depth[a]){
            for (int j = 19; j >= 0; j--){
                if (depth[pred[b1][j]] > depth[a1]){
                    b1 = pred[b1][j];
                }
            }
            b1 = pred[b1][0];
        }
        else{
            if (depth[a] > depth[b]){
                for (int j = 19; j >= 0; j--){
                    if (depth[pred[a1][j]] > depth[b1]){
                        a1 = pred[a1][j];
                    }
                }
                a1 = pred[a1][0];
            }
        }
        if (a1 == b1){
            return b1;
        }
        for (int j = 19; j >=0; j--){
            if (pred[a1][j] != pred[b1][j]){
                a1 = pred[a1][j];
                b1 = pred[b1][j];
            }
        }
        return pred[a1][0];
    }
    int dist(int v1, int v2){
        int v3 = lca(v1, v2);
        return (depth[v1] + depth[v2] - 2 * depth[v3]);
    }
    public void solve() throws IOException {
        // write your code here
        int n = nextInt();
        int k = nextInt();
        int[] p = new int[n];
        for (int i = 1; i < n; i++){
            p[i] = nextInt();
            p[i]--;
        }
        int[] a = new int[k];
        int[] b = new int[k];
        for (int i = 0; i < k; i++){
            a[i] = nextInt();
            b[i] = nextInt();
            a[i]--;
            b[i]--;
        }
        int[][] inters = new int[k][k];  // intersection
        pot = new ArrayList[n];
        for (int i = 0; i < n; i++){
            pot[i] = new ArrayList<Integer>();
        }
        for (int i = 1; i < n; i++){
            pot[p[i]].add(i);
        }
        depth = new int[n];   /// glubina
        tin = new int[n];    // time in
        timer = 0;
        dfs(0, 0);   /// dfs i glubiny
        int wsp;
        for (int i = 0; i < k; i++){
            if (tin[a[i]] > tin[b[i]]){
                wsp = a[i];
                a[i] = b[i];
                b[i] = wsp;
            }
        }
        pred = new int[n][20];     // predki
        for (int i = 0; i < n; i++){
            pred[i][0] = p[i];
        }
        for (int i = 0; i < n; i++){
            for (int j = 1; j <= 19; j++){
                pred[i][j] = pred[pred[i][j - 1]][j - 1];
            }
        }
        boolean[] good = new boolean[4];
        int[] x = new int[4];
        for (int i = 0; i < k; i++){
            for (int j = i + 1; j < k; j++){
                x[0] = lca(a[i], a[j]);
                x[1] = lca(a[i], b[j]);
                x[2] = lca(b[i], a[j]);
                x[3] = lca(b[i], b[j]);
                for (int u = 0; u < 4; u++){
                    good[u] = false;
                }
                for (int u = 0; u < 4; u++){
                    if ((dist(a[i], x[u]) + dist(b[i], x[u]) == dist(a[i],b[i])) && (dist(a[j], x[u]) + dist(b[j], x[u]) == dist(b[j],a[j]))){
                        good[u] = true;
                    }
                }
                for (int u1 = 0; u1 < 4; u1++){
                    for (int u2 = u1 + 1; u2 < 4; u2++){
                        if (good[u1] && good[u2]){
                            inters[i][j] = Math.max(inters[i][j], dist(x[u1],x[u2]));
                        }
                    }
                }
            }
        }
        int ve1 = 0;
        int ve2 = 1;
        for (int i = 0; i < k; i++){
            for (int j = i + 1; j < k; j++){
                if (inters[i][j] > inters[ve1][ve2]){
                    ve1 = i;
                    ve2 = j;
                }
            }
        }
        out.println(inters[ve1][ve2]);
        out.print(ve1 + 1);
        out.print(" ");
        out.print(ve2 + 1);
        out.close();
    }

    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 C().run();
    }

}
