#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)
{
    static int a = lca(x, y);
    return d[x] + d[y] - 2 * d[a];
}

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)
{
    return d[b] - d[a] + d[y] - d[a] - dst(b, y) - 2 * (d[x] - d[a]);
}

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();
    sort(q, q + k, [](pair<int, int> a, pair<int, int> b){return tin[a.f] < tin[b.f];});
    for (int i = 0; i < k; ++i)
    {
        h[i] = lca(q[i].f, q[i].s);
        b[q[i].s].pb(i);
        if (tin[q[i].f] > tin[q[i].s] || tin[q[i].s] > tout[q[i].f])
            b[q[i].f].pb(i);
    }
    ci();
//    for (int i = 0; i < k; ++i)
//        ord.pb(i);
//    random_shuffle(all(ord));
//    for (auto i: ord) if (clock() < TL)
//    for (int j = max(i - 2, 0) + !i, u, b, inter; j < k; ++j, j += j == i)
//    {
//        u = i, b = j;
//        if (tin[q[u].f] > tin[q[b].f])
//            swap(u, b);
//        inter = swdst(h[u], q[u].f, h[b], q[b].f) +
//                swdst(h[u], q[u].s, h[b], q[b].f) +
//                swdst(h[u], q[u].s, h[b], q[b].s) +
//                swdst(h[u], q[u].f, h[b], q[b].s);
//        if (ans < inter)
//            ans = inter, fp = u, sp = b;
//    }
    cout << ans / 2;
    cout << '\n' << fp + 1 << ' ' << sp + 1;
    return 0;
}
