import typing class DSU: ''' Implement (union by size) + (path halving) Reference: Zvi Galil and Giuseppe F. Italiano, Data structures and algorithms for disjoint set union problems ''' def __init__(self, n: int = 0) -> None: self._n = n self.parent_or_size = [-1] * n def merge(self, a: int, b: int) -> int: assert 0 <= a < self._n assert 0 <= b < self._n x = self.leader(a) y = self.leader(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x self.parent_or_size[x] += self.parent_or_size[y] self.parent_or_size[y] = x return x def same(self, a: int, b: int) -> bool: assert 0 <= a < self._n assert 0 <= b < self._n return self.leader(a) == self.leader(b) def leader(self, a: int) -> int: assert 0 <= a < self._n parent = self.parent_or_size[a] while parent >= 0: if self.parent_or_size[parent] < 0: return parent self.parent_or_size[a], a, parent = ( self.parent_or_size[parent], self.parent_or_size[parent], self.parent_or_size[self.parent_or_size[parent]] ) return a def size(self, a: int) -> int: assert 0 <= a < self._n return -self.parent_or_size[self.leader(a)] def groups(self) -> typing.List[typing.List[int]]: leader_buf = [self.leader(i) for i in range(self._n)] result: typing.List[typing.List[int]] = [[] for _ in range(self._n)] for i in range(self._n): result[leader_buf[i]].append(i) return list(filter(lambda r: r, result)) from heapq import * N, M = map(int, input().split()) A = list(map(int, input().split())) g = [] uf = DSU(N) for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 g.append((a, b, c)) uf.merge(a, b) inf = 10 ** 20 dist = [-inf] * N dist[0] = 0 for i in range(N + 1): for u, v, c in g: if dist[u] != -inf and dist[v] < dist[u] + A[v] - c: dist[v] = dist[u] + A[v] - c for u, v, c in g: if uf.same(0, u) and uf.same(N - 1, u) and dist[u] != -inf and dist[v] < dist[u] + A[v] - c: exit(print("inf")) print(dist[N - 1] + A[0] if dist[N - 1] > -inf else "inf")