n,m=map(int,input().split()) a=list(map(int,input().split())) path=[[] for _ in range(n)] for i in range(m): c,d=map(int,input().split()) if a[c-1]