# 標準入力された値を整数に変換する def INT(): return int(input()) # 標準入力された複数の値を整数に変換する def MI(): return map(int, input().split()) # 標準入力された複数の値を整数のリストに変換する def LI(): return list(map(int, input().split())) class UnionFind: def __init__(self, N): self.root = [_ for _ in range(N)] self.rank = [0] * N self.size = [1] * N def find(self, x): if self.root[x] == x: return x else: # 根を予め取得し,経路圧縮する self.root[x] = self.find(self.root[x]) return self.root[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return else: if self.rank[x] > self.rank[y]: self.size[x] += self.size[y] self.root[y] = x else: self.size[y] += self.size[x] self.root[x] = y if self.rank[x] == self.rank[y]: self.rank[y] += 1 def same(self, x, y): return self.find(x) == self.find(y) def getSizeOfSet(self, x): return self.size[self.find(x)] import heapq def dijkstra(n, G, start=0): INF = 10**18 dist = [INF] * n dist[start] = 0 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)] dsu = UnionFind(N) for _ in range(M): a, b, c = MI() a -= 1 b -= 1 G[a].append((b, A[b] - c)) if dsu.same(a, b): print("inf") exit(0) dsu.union(a, b) dist = dijkstra(N, G) print(dist[-1] + A[0])