m=lambda x:[*map(int,x.split())] A,B,*C=open(0) N,M=m(A) H=0,*m(B) G=[[]for i in range(N+1)] for s in C:a,b=m(s);G[a]+=b,;G[b]+=a, D=[] for c in 1,N: S=[-1e9]*-~N;S[c]=0;Q=[c] for t in Q: for n in G[t]: if H[n]>H[t]and S[n]<=S[t]:S[n]=S[t]+1;Q+=n, D+=S, print(max(-2,*map(sum,zip(*D)))+1)