## https://yukicoder.me/problems/no/2712 MAX_INT = 10 ** 18 from collections import deque def 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()) edges.append((a, b, c)) new_edges = [] for a, b, c in edges: new_edges.append((a, b, -A[b - 1] + c)) new_edges.append((0, 1, -A[0])) # ベルマンフォード costs = [MAX_INT] * (N + 1) costs[0] = 0 for i in range(N + 1): for a, b, c in new_edges: new_cost = costs[a] + c if costs[b] > new_cost: if i >= N: costs[b] = -MAX_INT else: costs[b] = new_cost next_nodes = [[] for _ in range(N + 1)] for a, b, _ in new_edges: next_nodes[b].append(a) queue = deque() queue.append(N) passed = [False] * ( N + 1) passed[N] = True while len(queue) > 0: v = queue.popleft() for w in next_nodes[v]: if not passed[w]: passed[w] = True queue.append(w) for i in range(N + 1): if passed[i] and costs[i] == -MAX_INT: print("inf") return print(-costs[N]) if __name__ == "__main__": main()