def bellmanFord(n, edges, s, inf=1 << 60): """ edges = [(from1, to1, cost1), (from2, to2, cost2), ...)] """ dist = [inf] * n dist[s] = 0 for _ in range(n): update = False for u, v, d in edges: if dist[u] != inf and dist[v] > dist[u] + d: dist[v] = dist[u] + d update = True if not update: return -dist[-1] bd = dist[-1] for _ in range(n): update = False for u, v, d in edges: if dist[u] != inf and dist[v] > dist[u] + d: dist[v] = dist[u] + d update = True if not update: return -dist[-1] if bd != dist[-1]: return "inf" return -dist[-1] n, m = map(int, input().split()) A = list(map(int, input().split())) edges = [] for i, a in enumerate(A): edges.append((2 * i, 2 * i + 1, -a)) for _ in range(m): a, b, c = map(int, input().split()) a -= 1 b -= 1 edges.append((2 * a + 1, 2 * b, c)) ans = bellmanFord(2 * n, edges, 0) print(ans)