# 標準入力された値を整数に変換する def INT(): return int(input()) # 標準入力された複数の値を整数に変換する def MI(): return map(int, input().split()) # 標準入力された複数の値を整数のリストに変換する def LI(): return list(map(int, input().split())) import heapq def dijkstra(n, G, start=0): MINF = -(10**18) dist = [MINF] * n dist[start] = A[start] pq = [] heapq.heappush(pq, (0, start)) visited = [False] * n while pq: now = heapq.heappop(pq)[1] visited[now] = True for nxt, cost in G[now]: if dist[nxt] < dist[now] + cost and not visited[nxt]: dist[nxt] = dist[now] + cost heapq.heappush(pq, (dist[now] + cost, nxt)) return dist N, M = MI() A = LI() G = [[] for i in range(N)] for _ in range(M): a, b, c = MI() a -= 1 b -= 1 G[a].append((b, A[b] - c)) dist = [] for i in range(N): d = dijkstra(N, G, i) dist.append(d) for i in range(N): for j in range(N): if i == j: continue if dist[0][i] >= 0 and dist[i][j] > 0 and dist[j][i] > 0: print("inf") exit() print(dist[0][N - 1])