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 bd = dist[:] 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] st = [] used = [False] * n for i in range(n): if bd[i] != dist[i]: dist[i] = None st.append(i) used[i] = True E = [[] for _ in range(n)] for u, v, d in edges: E[u].append(v) while st: v = st.pop() for u in E[v]: if not used[u]: used[u] = True st.append(u) dist[u] = None return dist 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)[-1] if ans is None: print("inf") else: print(-ans)