from heapq import * N, M = map(int, input().split()) A = list(map(int, input().split())) g = [[] for _ in range(N)] for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 g[a].append((b, c)) d = [-10 ** 18] * N d[0] = A[0] q = [(-A[0], 0)] while q: di, u = heappop(q) di = -di if di < d[u]: continue for v, c in g[u]: if di + A[v] - c > d[v] > -10 ** 18: exit(print("inf")) if di + A[v] - c > d[v]: d[v] = di + A[v] - c heappush(q, (-d[v], v)) print(d[N - 1])