def check(i, j, time_in, time_out):
    if time_in[i] < time_in[j] and time_out[i] > time_out[j]:
        return True
    return False


def dfs(u, prev, time, time_in, time_out, graf, previous, deep, deeps):
    deeps[u] = deep
    if u != 0:
        previous[u][0] = prev
    time_in[u] = time
    for v in graf[u]:
        if v != prev:
            time = dfs(v, u, time + 1, time_in, time_out, graf, previous, deep + 1, deeps)
    time += 1
    time_out[u] = time
    return time + 1


def up(v, n, previous, num):
    res = v
    i = num - 1
    path = 1
    for j in range(i):
        path *= 2
    while i >= 0:
        if n >= path:
            res = previous[res][i]
            n -= path
        i -= 1
        path //= 2
    return res


def lcp(u, v, previous, deeps, num):
    if deeps[u] < deeps[v]:
        u, v = v, u
    u = up(u, deeps[u] - deeps[v], previous, num)
    if v == u:
        return v
    else:
        i = num - 1
        while i >= 0:
            if previous[v][i] != previous[u][i]:
                v = previous[v][i]
                u = previous[u][i]
            i -= 1
        return previous[u][0]


def cross(u1, v1, u2, v2, previous, deep, num):
    p1 = lcp(u1, v1, previous, deep, num)
    p2 = lcp(u2, v2, previous, deep, num)
    res = cross2(p1, u1, p2, u2, previous, deep, num) 
    res += cross2(p1, u1, p2, v2, previous, deep, num) 
    res += cross2(p1, v1, p2, u2, previous, deep, num)
    res += cross2(p1, v1, p2, v2, previous, deep, num)
    return res


def cross2(p1, u1, p2, u2, previous, deep, num):
    if p1 == u1 or p2 == u2:
        return 0
    tmp =  lcp(p1, p2, previous, deep, num)
    tmp2 = lcp(u1, u2, previous, deep, num)
    if tmp == p1:
        res = deep[tmp2] - deep[p2]
        return max(0, res)
    if tmp == p2:
        res = deep[tmp2] - deep[p1]
        return max(0, res)
    return 0


def main():
    fin = open('twopaths.in', 'r')
    fout = open('twopaths.out', 'w')
    n, k = map(int, fin.readline().strip().split())
    num = 1
    tmp = 1
    while tmp < n:
        num += 1
        tmp *= 2
    graf = [None] * n
    for i in range(n):
        graf[i] = []
    tmp_arr = list(map(int, fin.readline().strip().split()))
    for i in range(n - 1):
        graf[tmp_arr[i] - 1].append(i + 1)
    time_in = [None] * n
    time_out = [None] * n
    previous = [None] * n
    for i in range(n):
        previous[i] = [None] * num
    previous[0] = [0] * num
    deeps = [None] * n
    tmp = dfs(0, -1, 0, time_in, time_out, graf, previous, 0, deeps)
    for i in range(1, num):
        for j in range(1, n):
            previous[j][i] = previous[previous[j][i - 1]][i - 1]
    #for i in range(n):
    #    for j in range(n):
    #        print(i, j, lcp(i, j, previous, deeps, num))
    men = [None] * k
    for i in range(k):
        men[i] = tuple(map(int, fin.readline().strip().split()))
        men[i] = (men[i][0] - 1, men[i][1] - 1)
    best = 0
    best_pair = (1, 2)
    for i in range(k):
        for j in range(i + 1, k):
            tmp = cross(men[i][0], men[i][1], men[j][0], men[j][1], previous, deeps, num)
            if tmp > best:
                best = tmp
                best_pair = (i + 1, j + 1)
    fout.write(str(best) + '\n' + str(best_pair[0]) + ' ' + str(best_pair[1]) + '\n')
    fin.close()
    fout.close()


main()