from atcoder.dsu import DSU from heapq import * N, M = map(int, input().split()) A = list(map(int, input().split())) g = [] uf = DSU(N) for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 g.append((a, b, c)) uf.merge(a, b) inf = 10 ** 20 dist = [-inf] * N dist[0] = 0 for i in range(N + 1): for u, v, c in g: if dist[u] != -inf and dist[v] < dist[u] + A[v] - c: dist[v] = dist[u] + A[v] - c for u, v, c in g: if uf.same(0, u) and dist[v] < dist[u] + A[v] - c: exit(print("inf")) print(dist[N - 1] + A[0] if dist[N - 1] > -inf else "inf")