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()) x-=1 y-=1 e+=[(x,y,z-a[x])] 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 if f==0: break print("inf" if f else -v[n-1]+a[n-1])