def solve(): N,M=map(int,input().split()) H=[-1]+list(map(int,input().split())) Sc=[[] for _ in range(N+1)] Sz=[[] for _ in range(N+1)] for j in range(M): x,y=map(int,input().split()) Sc[x].append(y) Sz[y].append(x) inf=float("inf") # チェリーちゃん DP_c=[[-inf,-inf] for _ in range(N+1)] DP_c[1][0]=0 for a in range(1,N+1): for b in Sc[a]: if ab: if H[a]-inf else -1 ans_z=max(DP_z[1]) if max(DP_z[1])>-inf else -1 print(ans_c, ans_z, sep="\n") solve()