import sys input = sys.stdin.readline from operator import itemgetter N,M=map(int,input().split()) H=list(map(int,input().split())) E=[tuple(map(int,input().split())) for i in range(M)] DP=[-1<<60]*N DP2=[-1<<60]*N # 次に下りのみ DP[0]=0 E.sort(key=itemgetter(0)) for x,y in E: x-=1 y-=1 if H[x]