import java.io.*;
import java.util.*;
  
public class c2 {
    static int prev[][];
    static ArrayList<Integer> edges[];
    static int time;
    static int exit[];
    static int start[];
    static int level[];
    static int cnt;
  
    static int la(int x, int lvl) {
        int cur = level[x];
        int x1 = x;
  
        for (int i = cnt - 1; i > -1; i--) {
            if (cur - (1 << i) >= lvl) {
                x1 = prev[x1][i];
                cur -= (1 << i);
            }
            if (cur == lvl) {
                break;
            }
        }
  
        return x1;
    }
  
    static int lca(int x, int y) {
        if (start[x] < start[y] && exit[y] < exit[x]) {
            return x;
        }
        if (start[y] < start[x] && exit[x] < exit[y]) {
            return y;
        }
  
        int x1 = x;
        int y1 = y;
  
        if (level[x1] < level[y1]) {
            y1 = la(y1, level[x1]);
        }
  
        if (level[x1] > level[y1]) {
            x1 = la(x1, level[y1]);
        }
  
        if (x1 == y1) {
            return x1;
        } else {
            int lvl = level[x1];
  
            for (int i = cnt - 1; i > -1; i--) {
                if (prev[x1][i] != prev[y1][i] && lvl >= (1 << i)) {
                    x1 = prev[x1][i];
                    y1 = prev[y1][i];
                    lvl = lvl - (1 << i);
                }
            }
  
            return prev[x1][0];
        }
    }
  
    static void dfs(int x) {
        start[x] = time;
        time++;
        for (int i : edges[x]) {
            level[i] = level[x] + 1;
            dfs(i);
        }
        exit[x] = time;
        time++;
    }
  
    static int sum(int y1, int x1, int y2, int x2) {
        if (start[x1] <= start[x2] && exit[x2] <= exit[x1]) {
            if (start[y1] >= start[x2] && exit[x2] >= exit[y1]) {
                return Math.max(level[lca(y1, y2)] - level[x2], 0);
            }
        }
  
        if (start[x2] <= start[x1] && exit[x1] <= exit[x2]) {
            if (start[y2] >= start[x1] && exit[x1] >= exit[y2]) {
                return Math.max(level[lca(y1, y2)] - level[x1], 0);
            }
        }
  
        return 0;
    }
  
    public void solve() throws IOException {
        int n = nextInt();
        int k = nextInt();
  
        int pr[] = new int[n];
        edges = new ArrayList[n];
        level = new int[n];
        time = 0;
  
        exit = new int[n];
        start = new int[n];
  
        pr[0] = -1;
  
        for (int i = 0; i < n; i++) {
            edges[i] = new ArrayList();
        }
  
        for (int i = 1; i < n; i++) {
            pr[i] = nextInt() - 1;
  
            edges[pr[i]].add(i);
        }
  
        long q = 1;
        cnt = 0;
  
        while (q <= n) {
            q *= 2;
            cnt++;
        }
  
        prev = new int[n][cnt];
  
        for (int i = 0; i < n; i++) {
            prev[i][0] = pr[i];
        }
  
        for (int i = 1; i < cnt; i++) {
            for (int j = 0; j < n; j++) {
                int x = prev[j][i - 1];
  
                if (x != -1) {
                    prev[j][i] = prev[x][i - 1];
                } else {
                    prev[j][i] = -1;
                }
            }
        }
  
        level[0] = 0;
  
        dfs(0);
  
        long ans = 0;
        long x = 1;
        long y = 2;
  
        int lcap[] = new int[k];
        int a[] = new int[n];
        int b[] = new int[n];
 
        if (k > 5000){
            cnt = 5;
        }
         
        for (int i = 0; i < k; i++) {
            a[i] = nextInt() - 1;
            b[i] = nextInt() - 1;
  
            lcap[i] = lca(a[i], b[i]);
  
            for (int j = 0; j < i; j++) {
                int cur = 0;
                cur += sum(a[i], lcap[i], a[j], lcap[j]);
                if (cur == 0) {
                    cur += sum(a[i], lcap[i], b[j], lcap[j]);
                    cur += sum(b[i], lcap[i], a[j], lcap[j]);
                }
                cur += sum(b[i], lcap[i], b[j], lcap[j]);
  
                if (ans < cur) {
                    ans = cur;
  
                    x = i + 1;
                    y = j + 1;
                }
            }
        }
  
        out.println(ans);
        out.println(x + " " + y);
  
    }
  
    public void run() {
        try {
            br = new BufferedReader(new FileReader("twopaths.in"));
            out = new PrintWriter("twopaths.out");
  
            solve();
  
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
  
    static BufferedReader br;
    static StringTokenizer in;
    PrintWriter out;
  
    public static String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }
  
    public static 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 c2().run();
    }
  
}