from collections import deque import sys input = lambda: sys.stdin.readline().rstrip() N, M = map(int, input().split()) A = [int(a) - 1 for a in input().split()] X = [[] for i in range(N)] for _ in range(N - 1): x, y = map(int, input().split()) X[x-1].append(y-1) X[y-1].append(x-1) P = [-1] * N Q = deque([0]) R = [] while Q: i = deque.popleft(Q) R.append(i) for a in X[i]: if a != P[i]: P[a] = i X[a].remove(i) deque.append(Q, a) G = [0] * N # Grundy Number L = [[] for _ in range(N)] for i in R[::-1]: m = min(len(X[i]) + 2, 20) L[i] = [0] * m for j in X[i]: if G[j] < m: L[i][G[j]] += 1 for k in range(m): if not L[i][k]: G[i] = k break G_bu = G[:] for i in R[1:]: m = min(len(X[i]) + 2, 20) g = G[i] p = P[i] pg = G[p] if g < pg and L[p][g] == 1: pg = g if pg < m: L[i][pg] += 1 if pg == g: for k in range(g, m): if not L[i][k]: G[i] = k break s = 0 for a in A: s ^= G[a] if s == 0: print(-1, -1) else: for i, a in enumerate(A): if G[a] ^ s < G[a]: for b in X[a]: if G[a] ^ s == G_bu[b]: print(i+1, b+1) exit() print(i+1, P[a] + 1) exit()