from collections import deque n, m = map(int, input().split()) a = list(map(int, input().split())) e = [[] for _ in range(n)] e2 = [[] for _ in range(n)] for _ in range(m): u, v, c = map(int, input().split()) u -= 1 v -= 1 c = a[v] - c e[u].append([v, c]) e2[v].append(u) flg = [0] * n flg[-1] = 1 d = deque([n-1]) while d: u = d.popleft() for v in e2[u]: if flg[v]: continue flg[v] = 1 d.append(v) inf = 1 << 60 sat = [-inf] * n sat[0] = a[0] d = deque([0]) flg[0] |= 2 while d: u = d.popleft() for v, c in e[u]: if sat[v] < sat[u] + c: flg[v] |= 2 if sat[v] == -inf: d.append(v) sat[v] = sat[u] + c sat2 = sat[:] for u in range(n): for v, c in e[u]: if sat2[v] < sat2[u] + c and flg[u] == 3: print("inf") exit() print(sat[-1])