N,M=map(int,input().split()) A=list(map(int, input().split())) n=N def bellman_ford(s): d = [float('inf')]*n # 各頂点への最小コスト d[s] = 0 # 自身への距離は0 for i in range(n): update = False # 更新が行われたか for x, y, z in g: if d[y] > d[x] + z: d[y] = d[x] + z update = True if not update: break # 負閉路が存在 if i == n - 1: return -1 return d g=[] D=[[]for _ in range(N)];C=[] for _ in range(M): x,y,z=map(int,input().split()) x-=1;y-=1 C.append((x,y,z)) D[y].append(x) #g.append([x, y, -z]) from collections import deque d=deque() V=[-1]*N V[N-1]=1 d.append(N-1) while d: now=d.popleft() for nex in D[now]: if V[nex]==-1: V[nex]=1 d.append(nex) for x,y,z in C: if V[x]+V[y]==2: g.append((x,y,-A[y]+z)) #print(g,D) ans=bellman_ford(0) #print(ans) if ans==-1: print('inf') else: print(A[0]-ans[-1])