#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int operator & (unordered_set<unsigned long long> &a, unordered_set<unsigned long long> &b)
{
    int res = 0;
    for (auto e : a)
        if (b.count(e) == 1)
            res++;
    return res;
}

unsigned long long mp(unsigned long long a, unsigned long long b)
{
    if (a > b)
        swap(a, b);
    return a * 10000 + b;
}

unordered_set<unsigned long long> dfs(int p, int v, int f, vector<vector<int>> &g)
{
    unordered_set<unsigned long long> res;
    for (auto u: g[v])
    {
        if (u == f)
        {
            res.insert(mp(v, f));
            return res;
        }
        else if (u != p)
        {
            auto temp = dfs(v, u, f, g);
            if (temp.size() > 0)
            {
                temp.insert(mp(v, u));
                return temp;
            }
        }
    }
    return res;
}

int main() {
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    int n, k;
    scanf("%d %d", &n, &k);
    vector<vector<int>> g(n);
    for (int i = 1; i < n; i++)
    {
        int a;
        scanf("%d", &a);
        g[a - 1].push_back(i);
        g[i].push_back(a - 1);
    }
    vector<unordered_set<unsigned long long>> path(k);
    for (int i = 0; i < k; i++)
    {
        int a, b;
        scanf("%d %d", &a, &b);
        a--;
        b--;
        path[i] = dfs(-1, a, b, g);
    }
    int ans = 0, r1 = 1, r2 = 2;
    for (int i = 0; i < k; i++)
    {
        for (int j = i + 1; j < k; j++)
        {
            if ((path[i] & path[j]) > ans)
            {
                ans = (path[i] & path[j]);
                r1 = i + 1;
                r2 = j + 1;
            }
        }
    }
    cout << ans << "\n" << r1 << " " << r2;
}