import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random # O(EV) 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 = [] n,m = map(int,input().split()) n *= 2 alist = list(map(int,input().split())) for i in range(m): a,b,c = map(int,input().split()) a -= 1 b -= 1 g.append((a*2+1,b*2,c)) for i in range(n//2): g.append((i*2,i*2+1,-alist[i])) z = bellman_ford(0) print('inf' if z == -1 else -z[-1])