#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int maxn = 5e5;

int n, k;
vector<pair<int, int>> g[maxn];
int pa[maxn];
int is[maxn];
int b;

bool col(int v, int p = -1)
{
    if (v == b) {
        return 1;
    }
    for (auto &to: g[v]) {
        if (to.first != p) {
            if (col(to.first, v)) {
                is[to.second] = 1;
                return 1;
            }
        }
    }
    return 0;
}

int dfs(int v, int p = -1)
{
    if (v == b) {
        return 0;
    }
    for (auto &to: g[v]) {
        if (to.first != p) {
            int y;
            if ((y = dfs(to.first, v)) >= 0) {
                y += is[to.second];
                return y;
            }
        }
    }
    return -1;
}
pair<int, int> ks[maxn];

int main()
{
    freopen("twopaths.in", "r", stdin);
    freopen("twopaths.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> k;
    for (int i = 1; i < n; ++i) {
        int a;
        cin >> a;
        --a;
        pa[i] = a;
        g[a].push_back({i, i});
        g[i].push_back({a, i});
    }
    for (int i = 0; i < k; ++i) {
        cin >> ks[i].first >> ks[i].second;
        --ks[i].first;
        --ks[i].second;
    }
    int res = 0, ra = 0, rb = 1;
    for (int i = 0; i < k; ++i) {
        fill(is, is+n, 0);
        b = ks[i].second;
        col(ks[i].first);
        for (int j = i+1; j < k; ++j) {
            b = ks[j].second;
            int h = dfs(ks[j].first);
            if (h > res) {
                res = h;
                ra = i;
                rb = j;
            }
        }
    }
    cout << res << '\n' << ra+1 << ' ' << rb+1 << '\n';
    return 0;
}
