3 2
1 0 1
1 2
2 3
 10 10
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
6 7
8 3
6 4
4 2
9 2
5 10
9 8
10 7
5 1
6 2

2
1
2
 0

n, m = map(int, input().split())
d = [-123] + list(map(int, input().split()))
edges = []

for i in range(m):
    u, v = map(int, input().split())
    edges.append((u, v))


def gao():
    if 0 in d or -1 in d:
        return 0
    for i, edge in enumerate(edges):
        u, v = edge
        if d[u] == d[v]:
            return i
    return -1


print(gao())
