#include <bits/stdc++.h>

using namespace std;

namespace Alpha
{

bool frs[100];
bool scn[100];
bool us[100];

vector<int> g[100];

bool dfs(int v, int scnv, bool issec)
{
    if (us[v])
        return false;
    us[v] = true;
    if (v == scnv)
    {
        if (issec)
            scn[v] = true;
        else
            frs[v] = true;
        return true;
    }
    bool b = false;
    for (int i : g[v])
        b = b || dfs(i, scnv, issec);
    if (issec)
        scn[v] = b;
    else
        frs[v] = b;
    return b;
}

void sol(int n, int k)
{
    int par[n];
    for (int i = 1; i < n; ++i)
    {
         scanf("%d", &par[i]);
        --par[i];
        g[i].push_back(par[i]);
        g[par[i]].push_back(i);
    }
    int a[k], b[k];
    for (int i = 0; i < k; ++i)
    {
        scanf("%d%d", &a[i], &b[i]);
        --a[i], --b[i];
    }
    int mx1 = 0, mx2 = 1;
    int bestans = 1;
    for (int i = 0; i < k; ++i)
    {
        for (bool &i : frs)
            i = false;
        for (bool &i : us)
                i = false;
        dfs(a[i], b[i], false);
        for (int j = i + 1; j < k; ++j)
        {
            for (bool &i : scn)
                i = false;
            for (bool &i : us)
                i = false;
            dfs(a[j], b[j], true);
            int ch = 0;
            for (int mda = 0; mda < n; ++mda)
                if (frs[mda] && scn[mda])
                    ++ch;
            if (ch > bestans)
            {
                mx1 = i;
                mx2 = j;
                bestans = ch;
            }
        }
    }
    printf("%d\n%d %d\n", bestans - 1, mx1 + 1, mx2 + 1);
}

}

namespace Beta
{

int jump[100000][20];
vector<int> g[100000];
int timein[100000], timeout[100000];
int deep[100000];
int time = 0;

void dfs(int v)
{
   // cout << v << "v\n";
    timein[v] = time++;
    for (int i = 1; i < g[v].size(); ++i)
        dfs(g[v][i]);
    timeout[v] = time++;
}

int LCA(int v1, int v2)
{
    int jumpsize = 19;
    bool fl = true;
    int scnin = timein[v2];
    int scnout = timeout[v2];
    //cout << timein[v1] << " " << timeout[v1] << "\n";
    if (timein[v1] <= scnin && timeout[v1] >= scnout)
        return v1;
    while (fl)
    {
        while (jump[v1][jumpsize] == -1)
            --jumpsize;
        int h = jump[v1][jumpsize];
        while (jumpsize >= 0 && timein[h] <= scnin && timeout[h] >= scnout)
            if (--jumpsize >= 0)
                h = jump[v1][jumpsize];
        if (jumpsize == -1)
            return g[v1][0];
        v1 = h;
    }
}

void sol(int n, int k)
{
    for (int i = 0; i < 100000; ++i)
        g[i].resize(0);
    time = 0;
    deep[0] = 0;
    g[0].push_back(-1);
    for (int i = 1; i < n; ++i)
    {
        int a;
        scanf("%d", &a);
        --a;
        g[a].push_back(i);
        g[i].push_back(a);
        deep[i] = deep[a] + 1;

    }
    int a[k], b[k];
    for (int i = 0; i < k; ++i)
    {
        scanf("%d%d", &a[i], &b[i]);
        --a[i], --b[i];
        if (a[i] > b[i])
            swap(a[i], b[i]);
    }
    for (int i = 0; i < n; ++i)
        jump[i][0] = g[i][0];

    for (int i = 1; i < 20; ++i)
    {
        for (int j = 0; j < n; ++j)
            if (jump[j][i - 1] != -1)
                jump[j][i] = jump[jump[j][i - 1]][i - 1];
            else
                jump[j][i] = -1;
    }
    dfs(0);
    //cout << LCA(a[0], b[0]) << "lca\n";
    int mx1 = 0, mx2 = 1;
    int bestans = 0;
    for (int i = 0; i < k; ++i)
    {
        for (int j = i + 1; j < k; ++j)
        {
            int fr = LCA(a[i], a[j]);
            int sc = LCA(b[i], b[j]);
            int ans;
            if (fr != a[i] && fr != a[j])
                ans = 0;
            else
                ans = -deep[max(a[i], a[j])] + deep[sc];
            //cout << deep[a[i]] << " " << deep[sc] << "\n";
            //cout << ans << "ans\n";
            if (ans > bestans)
            {
                mx1 = i;
                mx2 = j;
                bestans = ans;
            }
        }
    }
    printf("%d\n%d %d\n\n", bestans, mx1 + 1, mx2 + 1);
}
}


int main()
{
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    int n, k;
    while (scanf("%d%d", &n, &k) == 2)
    {
        if (n <= 100 && k <= 100)
            Alpha::sol(n, k);
        else
            Beta::sol(n, k);
    }
    return 0;
}
