from collections import deque N, M = map(int, input().split()) A = list(map(int, input().split())) edge = [list(map(int, input().split())) for _ in range(M)] for i in range(M): edge[i][2] = A[edge[i][1]-1]-edge[i][2] INF = float("inf") dist = [-INF]*N dist[0] = A[0] for i in range(N): flag = False for j in range(M): a, b, c = edge[j] if dist[a-1]+c > dist[b-1]: dist[b-1] = dist[a-1]+c flag = True if not flag: print(dist[-1]) break else: d = dist[:] for i in range(M): a, b, c = edge[i] if d[a-1]+c > d[b-1]: d[b-1] = d[a-1]+c G = [[] for _ in range(N)] for i in range(M): a, b, c = edge[i] G[a-1].append(b-1) visited = [False]*N for i in range(N): if d[i] != dist[i] and not visited[i]: visited[i] = True que = deque() que.append(i) while que: n = que.popleft() if n == N-1: exit(print("inf")) for v in G[n]: if not visited[v]: visited[v] = True que.append(v) print(dist[-1])