from heapq import * N, M = map(int, input().split()) A = list(map(int, input().split())) g = [] for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 g.append((a, b, c - A[b])) d = [10 ** 100]*N d[0] = 0 for i in range(N): update = False for x, y, z in g: if d[y] > d[x] + z: d[y] = d[x] + z update = True if not update: break if i == N - 1: exit(print("inf")) print(A[0] - d[N - 1])