def Belman_Ford(n,w,es,x): #負の経路の検出付き #n:頂点数, w:辺の数, es[i]: [辺の始点,辺の終点,辺のコスト] #x:スタート地点 #戻り値 負閉路がある場合-1、sから各頂点のコストのリスト d = [-float("inf")] * n d[x] = 0 update = 0 #この始点はどこでもよい for i in range(n): update = 0 for j in range(w): start,finish,cost = es[j] if d[finish] < d[start] + cost: update = 1 d[finish] = d[start] + cost if i == n-1: return -1 if update == 0: return d N,M = map(int,input().split()) A = list(map(int,input().split())) INF = -float('inf') es = [] for _ in range(M): a,b,c = map(int,input().split()) a -= 1 b -= 1 es.append((a,b,A[b] - c)) x = Belman_Ford(N,len(es),es,0) if x == -1: print("inf") else: print(A[0] + x[-1])