#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <set>

using std::cin;
using std::cout;
using std::cerr;

using std::set;
using std::vector;
using std::string;
using std::pair;
using std::make_pair;

using std::min;
using std::max;
using std::abs;

template <typename T>
T input() {
    T res;
    cin >> res;
    return res;
}

vector<vector<uint32_t>> parents;
vector<vector<uint32_t>> graph;
vector<pair<uint32_t, uint32_t>> times;
vector<uint32_t> depth;
vector<pair<uint32_t, uint32_t>> ships;
uint32_t cur_time = 0;

uint32_t best_ans = 0;
pair<uint32_t, uint32_t> the_ans = {0, 1};

vector<vector<uint32_t>> ships_by_lca;
vector<vector<uint32_t>> ships_by_end;

void dfs(uint32_t v) {
    times[v].first = cur_time++;
    for (auto u: graph[v])
        dfs(u);
    times[v].second = cur_time++;
}

bool is_parent(uint32_t v, uint32_t u) {
    return times[v].first <= times[u].first and times[u].second <= times[v].second;
}

uint32_t lca_of(uint32_t v, uint32_t u) {
    if (is_parent(v, u))
        return v;
    for (int32_t i = parents.size() - 1; i >= 0; --i)
        if (not is_parent(parents[i][v], u))
            v = parents[i][v];

    return parents[0][v];
}

bool is_on_path(uint32_t u, uint32_t v, uint32_t uv, uint32_t w) {
    return is_parent(uv, w) and (is_parent(w, u) or is_parent(w, v));
}

uint32_t abs(uint32_t u, uint32_t v) {
    return u >= v ? u - v : v - u;
}

struct tin_cmp {
    bool operator()(pair<uint32_t, uint32_t> u, pair<uint32_t, uint32_t> v) const {
        if (times[u.first].first < times[v.first].first)
            return true;
        return times[u.first].first == times[v.first].first and u.second < v.second;
    }
};

void update_ans(uint32_t id1, uint32_t id2, uint32_t nans) {
    if (nans > best_ans)
        best_ans = nans, the_ans = {id1, id2};
}

set<pair<uint32_t, uint32_t>, tin_cmp> dfs2(uint32_t v) {
    set<pair<uint32_t, uint32_t>, tin_cmp> cur;
    for (uint32_t u: graph[v]) {
        auto other = dfs2(u);
        if (not (other.size() <= cur.size()))
            std::swap(other, cur);

        for (auto elem: other) {
            cur.insert(elem);
        }
    }

    // erase obsolete
    for (uint32_t id: ships_by_lca[v]) {
        for (auto z: {ships[id].first, ships[id].second}) {
            auto it = cur.find({z, id});
            if (it != cur.end()) {
                auto it2 = std::next(it);
                if (it2 != cur.end()) {
                    update_ans(it->second, it2->second, depth[lca_of(it->first, it2->first)] - depth[v]);
                }
                if (it != cur.begin()) {
                    it2 = std::prev(it);
                    update_ans(it->second, it2->second, depth[lca_of(it->first, it2->first)] - depth[v]);
                }

                cur.erase(it);
            }
        }
    }
    // add new.
    for (uint32_t id: ships_by_end[v]) {
        cur.insert({v, id});
    }
    return std::move(cur);
}

int main() {
#ifndef LOCAL
#define TASK "twopaths"
    freopen(TASK ".in", "r", stdin);
    freopen(TASK ".out", "w", stdout);
#endif
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    uint32_t n = input<uint32_t>();
    ships.resize(input<uint32_t>());

    uint32_t log_n = 1;
    for (; (1u << log_n) < n; ++log_n) { }

    parents.resize(log_n + 1, vector<uint32_t>(n));
    graph.resize(n, vector<uint32_t>());
    times.resize(n);
    depth.resize(n, 0);
    ships_by_lca.resize(n);
    ships_by_end.resize(n);

    for (uint32_t i = 1; i != n; ++i) {
        uint32_t p = input<uint32_t>() - 1;

        graph[p].push_back(i);
        depth[i] = depth[p] + 1;
        parents[0][i] = p;
    }

    dfs(0);

    for (uint32_t k = 1; k < parents.size(); ++k)
        for (uint32_t i = 0; i != n; ++i)
            parents[k][i] = parents[k - 1][parents[k - 1][i]];

    bool only_important = true;
    for (uint32_t i = 0; i != ships.size(); ++i) {
        ships[i].first = input<uint32_t>() - 1;
        ships[i].second = input<uint32_t>() - 1;

        uint32_t lca = lca_of(ships[i].first, ships[i].second);

        if (not (lca == ships[i].first or lca == ships[i].second))
            only_important = false;

        ships_by_lca[lca].push_back(i);
        if (ships[i].first != lca)
            ships_by_end[ships[i].first].push_back(i);
        if (ships[i].second != lca)
            ships_by_end[ships[i].second].push_back(i);
    }

    dfs2(0);

    if (not only_important)
    for (uint32_t v = 0; v != n; ++v) {
        for (uint32_t i = 0; i != ships_by_lca[v].size(); ++i)
            for (uint32_t j = i + 1; j != ships_by_lca[v].size(); ++j) {
                vector<uint32_t> verts;
                for (uint32_t u: {ships[ships_by_lca[v][i]].first, ships[ships_by_lca[v][i]].second})
                    for (uint32_t w: {ships[ships_by_lca[v][j]].first, ships[ships_by_lca[v][j]].second}) {
                        uint32_t l = lca_of(u, w);
                        if (l != v)
                            verts.push_back(l);
                    }
                if (verts.size() == 2)
                    update_ans(ships_by_lca[v][i], ships_by_lca[v][j], depth[verts[0]] + depth[verts[1]] - 2 * depth[v]);
            }
    }

    cout << best_ans << "\n";
    cout << the_ans.first + 1 << " " << the_ans.second + 1 << "\n";

    return 0;
}