from collections import defaultdict, deque def bellman_ford(n: int, adj: defaultdict): dists = [INF] * n dists[0] = 0 # 始点 negative_nodes = set() # 負閉路のノード for i in range(n): for v in range(n): if dists[v] == INF: continue for to, c in adj[v]: if dists[to] > dists[v] + c: dists[to] = dists[v] + c if i == n-1: negative_nodes.add(to) return dists, negative_nodes INF = 1 << 60 N, M = map(int, input().split()) A = list(map(int, input().split())) adj = defaultdict(list) r_adj = defaultdict(list) for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 adj[a].append((b, -(A[b] - c))) r_adj[b].append(a) # 頂点 start から到達可能な頂点を求める def find_reachables(start, adj): q = deque([start]) used = set() while q: v = q.popleft() if v in used: continue used.add(v) for to in adj[v]: if to in used: continue q.append(to) return used dists, negative_nodes = bellman_ford(N, adj) reachables = find_reachables(N-1, r_adj) # N-1 から到達可能なノード if any(v in reachables for v in negative_nodes): print('inf') else: print(-dists[N-1] + A[0])