n,m=map(int,input().split()) a=list(map(int,input().split())) e=[] for i in range(m): x,y,z=map(int,input().split()) e+=[(x-1,y-1,z-a[x-1])] X=10**20 v=[X]*n v[0]=0 for i in range(n): f=0 for x,y,z in e: if v[y]>v[x]+z: v[y]=v[x]+z f=1 print("inf" if f else -v[n-1]+a[n-1])