#define first f
#define second s
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <ctime>
#define all(a) begin(a), end(a)
#define pb push_back

using namespace std;

const int N = 200000, lgN = 18;
int n, k, tin[N], tout[N], d[N], a[lgN + 1][N], *p = a[0], md1[N], md2[N], mp1[N], mp2[N], t, ans, h[N], fp, sp = 1;
vector<int> son[N], ord, b[N];
pair<int, int> q[N];

void cd(int v = 0, int d = 0)
{
    ::d[v] = d;
    tin[v] = ++t;
    for (auto i: son[v])// if (!tin[i])
        cd(i, d + 1);
    tout[v] = ++t;
}

void lcac()
{
    for (int d = 0; d + 1 < lgN; ++d)
    for (int i = 0; i < n; ++i)
        a[d + 1][i] = a[d][a[d][i]];
}

inline bool ia(int a, int b)
{
    return tin[a] <= tin[b] && tin[b] <= tout[a];
}

int lca(int x, int y)
{
    for (int d = lgN - 1; d > -1; --d)
        if (!ia(a[d][x], y))
            x = a[d][x];
    for (int d = lgN - 1; d > -1; --d)
        if (!ia(a[d][y], x))
            y = a[d][y];
    if (!ia(x, y))
        return p[x];
    else if (!ia(y, x))
        return p[y];
    else
        return x;
}

int dst(int x, int y)
{
    return d[x] + d[y] - 2 * d[lca(x, y)];
}

void ci(int v = 0)
{
    md1[v] = md2[v] = 1e9;
    for (auto i: son[v])
    {
        ci(i);
        if (md1[v] > md1[i])
            if (md1[v] > md2[i])
                md2[v] = md2[i], md1[v] = md1[i],
                mp2[v] = mp2[i], mp1[v] = mp1[i];
            else
                md2[v] = md1[v], md1[v] = md1[i],
                mp2[v] = mp1[v], mp1[v] = mp1[i];
        else if (md2[v] > md1[i])
            md2[v] = md1[i],
            mp2[v] = mp1[i];
    }
    for (auto i: b[v])
        if (md1[v] > d[h[i]])
            md2[v] = md1[v], md1[v] = d[h[i]],
            mp2[v] = mp1[v], mp1[v] = i;
        else if (md2[v] > d[h[i]])
            md2[v] = d[h[i]],
            mp2[v] = i;
    if (ans < 2 * d[v] - md1[v] - md2[v])
        ans = 2 * d[v] - md1[v] - md2[v],
        fp = mp1[v], sp = mp2[v];
}

inline int swdst(int a, int b, int x, int y)
{
    if (dst(a, x) + dst(x, b) == dst(a, b) ||
        dst(a, y) + dst(y, b) == dst(a, b) ||
        dst(x, a) + dst(a, y) == dst(x, y) ||
        dst(x, b) + dst(b, y) == dst(x, y))
        return max(0, d[b] - d[a] + d[y] - d[a] - dst(b, y) - 2 * (d[x] - d[a]));
    else
        return 0;
}

//const int sN = 4001;
int mrk[N];

void mark(int a, int b)
{
    ++t;
    while (!ia(a, b))
        mrk[a] = t, a = p[a];
    while (b != a)
        mrk[b] = t, b = p[b];
    mrk[b] = t, b = p[b];
}

int marked(int a, int b)
{
    int ans = 0;
    while (!ia(a, b))
        ans += mrk[a] == t, a = p[a];
    while (b != a)
        ans += mrk[b] == t, b = p[b];
    ans += mrk[b] == t, b = p[b];
    return ans;
}

int main()
{
    ifstream cin("twopaths.in");
    ofstream cout("twopaths.out");
    cin >> n >> k;
    for (int i = 1; i < n; ++i)
        cin >> p[i], son[--p[i]].pb(i);
    clock_t TL = 1.9 * CLOCKS_PER_SEC;
    cd();
    for (int i = 0; i < k; ++i)
    {
        cin >> q[i].f >> q[i].s, --q[i].f, --q[i].s;
        if (tin[q[i].f] > tin[q[i].s])
            swap(q[i].f, q[i].s);
    }
    lcac();
    for (int i = 0; i < k; ++i)
    for (int j = 0; j < k; ++j)
    {
        if (tin[q[i].f] > tin[q[j].f])
            continue;
        int inter = swdst(h[i], q[i].f, h[j], q[j].f) +
                swdst(h[i], q[i].s, h[j], q[j].f) +
                swdst(h[i], q[i].s, h[j], q[j].s) +
                swdst(h[i], q[i].f, h[j], q[j].s);
        if (ans < inter)
            ans = inter, fp = i, sp = j;
    }
    cout << max(ans / 2, 0);
    cout << '\n' << fp + 1 << ' ' << sp + 1;
    return 0;
}
