fin = open('twopaths.in', 'r')
fout = open('twopaths.out', 'w')
input = fin.readline

def dfs(v, t, path):
    global a, b, path1, path2, was
    if v == b:
        if t == 1: path1 = path.copy()
        if t == 2: path2 = path.copy()
        return
    was[v] = 1
    for u in g[v]:
        if not was[u]:
            ed = min(u, v), max(u, v)
            dfs(u, t, path | {ed})

def f(i, j):
    global a, b, path1, path2, was
    path1, path2 = set(), set()
    a, b = c[i]
    was = [0] * (n + 1)
    dfs(a, 1, set())
    a, b = c[j]
    was = [0] * (n + 1)
    dfs(a, 2, set())
    res = len(path1 & path2)
    return res

read = lambda: map(int, input().split())
n, k = read()
p = [0] + list(read())
c = [tuple(read()) for i in range(k)]
g = [list() for i in range(n + 1)]
for i in range(1, n + 1):
    if i != 1: g[i].append(p[i - 1])
    g[p[i - 1]].append(i)
    
if n <= 100 and k <= 100:
    Max = -1
    ans = -1, -1
    a, b = -1, -1
    was = [0] * (n + 1)
    path1, path2 = set(), set()
    for i in range(k):
        for j in range(i + 1, k):
            cur = f(i, j)
            if cur > Max:
                Max = cur
                ans = i + 1, j + 1
else:
    from collections import Counter
    d = Counter()
    dnum = dict()
    s = set()
    Max = 0
    ans = -1, -1
    for i in range(k):
        a, b = c[i]
        if (a, b) in s:
            Max = 2
            ans = i + 1, -1
            break
        s.add((a, b))
        if b in g[a]:
            if a > b: ed = b, a
            else: ed = a, b
            d[(a, b)] += 1
        else:
            ed1 = tuple(sorted((a, g[a])))
            ed2 = tuple(sorted((b, g[b])))
            d[ed1] += 1
            d[ed2] += 1
            if dnum.get(ed1) == None: dnum[ed1] = []
            if dnum.get(ed2) == None: dnum[ed2] = []
            dnum[ed1].append(i + 1)
            dnum[ed2].append(i + 1)
            if d[ed1] == 2:
                Max = 1
                ans = dnum[ed1]
            if d[ed2] == 2:
                Max = 1
                ans = dnum[ed2]            
    if Max == 2:
        for i in range(k):
            if c[i] == c[ans[0] - 1]:
                ans = ans[0], i + 1
                break
    elif Max == 1:
        ...
    else:
        ans = 1, 2
        
    

print(Max, file = fout)
print(*ans, file = fout)

fin.close()
fout.close()