# 標準入力された値を整数に変換する def INT(): return int(input()) # 標準入力された複数の値を整数に変換する def MI(): return map(int, input().split()) # 標準入力された複数の値を整数のリストに変換する def LI(): return list(map(int, input().split())) 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, c - A[b])) MINF = 10**18 dist = [MINF] * N dist[0] = -A[0] exist_negative_cycle = False for i in range(N): update = False for u in range(N): if dist[u] == MINF: continue for v, c in G[u]: if dist[v] > dist[u] + c: dist[v] = dist[u] + c update = True if not update: break if i == N - 1 and update: exist_negative_cycle = True for i in range(N): for u in range(N): if dist[u] == MINF: continue for v, c in G[u]: threshold = dist[u] + c if threshold < dist[v]: dist[v] = -MINF ans = -dist[N - 1] print(ans if dist[N - 1] != -MINF else "inf")