from collections import namedtuple Edge = namedtuple("Edge", ["from_", "to", "cost"]) def bellman_ford(st, dist, edges): N = len(dist) for i in range(N): dist[i] = -float('inf') dist[st] = 0 for _ in range(N): update = False for e in edges: if dist[e.to] < dist[e.from_] + e.cost: dist[e.to] = dist[e.from_] + e.cost update = True if not update: return True return False if __name__ == "__main__": N, M = map(int, input().split()) A = list(map(int, input().split())) edges = [] for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 edges.append(Edge(a + N, b, -c)) for i in range(N): edges.append(Edge(i, i + N, A[i])) dist = [-float('inf')] * (2 * N) f = bellman_ford(0, dist, edges) if f: print(dist[2 * N - 1]) else: print("inf")