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

using namespace std;
vector<int> p;
vector<pair<int, int> > t;
vector<vector<int> > graph;
vector<vector<int> > dp;
vector<int> depth;

struct d
{
    int a, b, c;
    d(){};
    d(int x, int y, int z)
    {
        a = x;
        b = y;
        c = z;
    }
};

int log_ ;

int time_ = 0;

void dfs(int v)
{
    t[v].first = time_++;
    for (int i = 0; i < graph[v].size(); i++)
    {
        depth[graph[v][i]] = depth[v] + 1;
        dfs(graph[v][i]);
    }
    t[v].second = time_;
}

bool pred(int v, int u)
{
    return (t[v].first <= t[u].first && t[u].second <= t[v].second);
}

int f(int v, int u)
{
    if (pred(v, u))
        return v;
    if (pred(u, v))
        return u;
    int a = v;
    for (int i = log_ - 1; i >= 0; i--)
    {
        //cout << a << " " << u << " " << dp[a][i] << endl;
        if (!pred(dp[a][i], u))
        {
            a = dp[a][i];
        }
    }
    //cout << p[a] << endl;
    return p[a];
}

int main()
{
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    int n, k;
    cin >> n >> k;
    log_ = ceil(log2(n)) + 1;
    p.resize(n);
    graph.resize(n);
    depth.resize(n, 0);
    t.resize(n);
    dp.resize(n);
    for (int i = 0; i < n; i++)
    {
        dp[i].resize(log_);
    }
    p[0] = 0;
    for (int i = 0; i < n - 1; i++)
    {
        int x;
        cin >> x;
        x--;
        p[i + 1] = x;
        graph[p[i + 1]].push_back(i + 1);
    }
    for (int i = 0; i < n; i++)
    {
        dp[i][0] = p[i];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 1; j < dp[i].size(); j++)
        {
            dp[i][j] = dp[dp[i][j - 1]][j - 1];
        }
    }
    /*for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < log_; j++)
            cout << dp[i][j] << " ";
        cout << endl;
    }*/
    dfs(0);
    vector<d> arr;
    for (int i = 0; i < k; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        int c = f(a, b);
        //cout << a << " " << b << " " << c << endl;
        arr.push_back(d(a, b, c));
    }
    /*for (int i = 0; i < n; i++)
        cout << depth[i] << " ";
    cout << endl;*/
    int maxi = 0;
    pair<int, int> ans;
    ans.first = 0;
    ans.second = 1;
    for (int i = 0; i < k; i++)
    {
        for (int j = i + 1; j < k; j++)
        {
            int res = 0;
            if (pred(arr[i].c, arr[j].c))
            {
                int v;
                v = f(arr[i].a, arr[j].a);
                if (pred(arr[j].c, v))
                {
                    res += depth[v] - depth[arr[j].c];
                }
                v = f(arr[i].a, arr[j].b);
                if (pred(arr[j].c, v))
                {
                    res += depth[v] - depth[arr[j].c];
                }
                v = f(arr[i].b, arr[j].a);
                if (pred(arr[j].c, v))
                {
                    res += depth[v] - depth[arr[j].c];
                }
                v = f(arr[i].b, arr[j].b);
                //cout << v << endl;
                if (pred(arr[j].c, v))
                {
                    //cout << "1!!!!" << endl;
                    //cout << depth[arr[j].c] << " " << depth[v] << endl;
                    res += depth[v] - depth[arr[j].c];
                }
            }
            else if (pred(arr[j].c, arr[i].c))
            {
                int v;
                v = f(arr[i].a, arr[j].a);
                if (pred(arr[i].c, v))
                {
                    res += depth[v] - depth[arr[i].c];
                }
                v = f(arr[i].a, arr[j].b);
                if (pred(arr[i].c, v))
                {
                    res += depth[v] - depth[arr[i].c];
                }
                v = f(arr[i].b, arr[j].a);
                if (pred(arr[i].c, v))
                {
                    res += depth[v] - depth[arr[i].c];
                }
                v = f(arr[i].b, arr[j].b);
                if (pred(arr[i].c, v))
                {
                    res += depth[v] - depth[arr[i].c];
                }
            }
            if (res > maxi)
            {
                maxi = res;
                ans.first = i;
                ans.second = j;
            }
        }
    }
    cout << maxi << endl;
    cout << ans.first + 1 << " " << ans.second + 1 << endl;
    return 0;
}
