#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

const int MAX_N = 2e5;
const int MAX_LOGN = 20;
const int MAX_K = 2e5;

int t = 0;
int n, k;

int tIn[MAX_N];
int tOut[MAX_N];
bool seen[MAX_N];
vector<int> g[MAX_N];
pair<int, int> paths[MAX_K];
int par[MAX_N];
int height[MAX_N];
int pp[MAX_N][MAX_LOGN];

void readData(ifstream &fin) {
    fin >> n >> k;
    par[0] = 0;
    for (int v = 1; v < n; v++) {
        int p;
        fin >> p;
        par[v] = p - 1;
        g[p - 1].push_back(v);
    }

    for (int i = 0; i < k; i++) {
        int a, b;
        fin >> a >> b;
        paths[i] = make_pair(a - 1, b - 1);
    }
}

void calcPP(int v) {
    pp[v][0] = par[v];
    for (int i = 1; i < MAX_LOGN; i++) {
        pp[v][i] = pp[pp[v][i - 1]][i - 1];
    }
}

void dfs(int v) {
    calcPP(v);
    seen[v] = true;
    tIn[v] = t++;
    for (auto u: g[v]) {
        height[u] = height[v] + 1;
        dfs(u);
    }
    tOut[v] = t++;
}


inline bool isParent(int v, int u) { // V--\__u
    return tIn[v] <= tIn[u] and tOut[u] <= tOut[v];
}

inline int commonParent(int v, int u) {
    if (isParent(u, v)) return u;

    //while (!isParent(v, u)) v = par[v];

    int i = MAX_LOGN - 1;
    while (!isParent(v, u)) {
        while (i > 0 and isParent(pp[v][i], u)) i--;
        v = pp[v][i];
    }


    return v;
}

inline int commonEdges(int v, int u) {
    if (!isParent(v, u)) swap(v, u);
    if (!isParent(v, u)) return 0;

    return height[u] - height[v];
}

inline int commonEdges(int A, int a, int B, int b) {
    /*
    if (!isParent(A, a)) swap(A, a);
    if (!isParent(B, b)) swap(B, b);
    */
    if (!isParent(A, B)) {
        swap(A, B);
        swap(a, b);
    }
    if (!isParent(A, B)) return 0;
    if (isParent(a, B)) return 0;

    int top = B;
    int bottom = commonParent(a, b);
    if (!isParent(top, bottom)) return 0;
    return commonEdges(top, bottom);
}

inline int commonEdgesPath(int a1, int a2, int b1, int b2) {
    int A = commonParent(a1, a2), B = commonParent(b1, b2);
    return commonEdges(A, a1, B, b1) + commonEdges(A, a1, B, b2) + commonEdges(A, a2, B, b1) + commonEdges(A, a2, B, b2);
}

bool comp(const pair<int, int> p1, const pair<int, int> p2) {
    return height[p1.second] - height[p1.first] > height[p2.second] - height[p2.first];
}

int main() {
    for (int i = 0; i < MAX_N; i++) seen[i] = false;
    ifstream fin("twopaths.in");
    ofstream fout("twopaths.out");

    readData(fin);
    height[0] = 0;
    dfs(0);
    /*
    for (int v = 0; v < n; v++) {
        cout << v << ": " << edges[v] << " " << height[v] << " | " << tIn[v] << " " << tOut[v] << endl;
        for (int i = 0; i < 10; i++) {
            cout << pp[v][i] << " ";
        }
        cout << endl;
    }

    for (int i = 110; i < 100; i++) {
        int v, u;
        cin >> v >> u;
        cout << commonParent(v, u) << endl;
    }

    for (int i = 0; i < 100; i++) {
        int A, a, B, b;
        cin >> A >> a >> B >> b;
        cout << commonEdgesPath(A, a, B, b) << endl;
    }
    */

    int ans = 0;
    int p1 = 0, p2 = 1;

    if (k > 5000) {
        for (int i = 0; i < k; i++) {
            if (!isParent(paths[i].first, paths[i].second)) swap(paths[i].first, paths[i].second);
        }


        //sort(paths, paths + k);

        for (int i = 0; i < k; i++) {
            int a1 = paths[i].first, a2 = paths[i].second;
            if (height[a2] - height[a1] < ans) continue;
            for (int j = i + 1; j < k; j++) {
                int b1 = paths[j].first, b2 = paths[j].second;
                if (height[b2] - height[b1] < ans) continue;

                int ce = commonEdges(a1, a2, b1, b2);
                if (ce > ans) {
                    ans = ce;
                    p1 = i;
                    p2 = j;
                }
            }
        }
    } else {
        for (int i = 0; i < k; i++) {
            int a1 = paths[i].first, a2 = paths[i].second;
            int A = commonParent(a1, a2);
            if (height[a1] - height[A] + height[a2] - height[A] < ans) continue;
            for (int j = i + 1; j < k; j++) {
                int b1 = paths[j].first, b2 = paths[j].second;
                int B = commonParent(b1, b2);
                if (height[b1] - height[B] + height[b2] - height[B] < ans) continue;

                int ce = commonEdges(A, a1, B, b1) + commonEdges(A, a1, B, b2) + commonEdges(A, a2, B, b1) + commonEdges(A, a2, B, b2);
                if (ce > ans) {
                    ans = ce;
                    p1 = i;
                    p2 = j;
                }
            }
        }
    }
    fout << ans << endl;
    fout << p1 + 1 << " " << p2 + 1 << endl;
    fin.close();
    fout.close();
    return 0;
}
