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 p=y if f==0: print(-v[-1]+a[-1]) else: E=[[] for i in range(n)] for x,y,z in e: E[x]+=[y] q=[p] u=[0]*n u[p]=1 for s in q: for t in E[s]: if u[t]==0: u[t]=1 q+=[t] print(-v[-1]+a[-1] if u[-1]==0 else "inf")