n, m = map(int, input().split()) a = list(map(int, input().split())) g = [[] for _ in range(2 * n)] g_inv = [[] for _ in range(2 * n)] for i in range(n): g[i].append((i + n, -a[i])) g_inv[i + n].append(i) for _ in range(m): a, b, c = map(int, input().split()) a -= 1 b -= 1 g[a + n].append((b, c)) g_inv[b].append(a + n) reachable = [False] * (2 * n) reachable[-1] = True stack = [2 * n - 1] while stack: u = stack.pop() for v in g_inv[u]: if not reachable[v]: reachable[v] = True stack.append(v) INF = 10 ** 18 dist = [INF] * (2 * n) dist[0] = 0 for _ in range(2 * n - 1): for u in range(2 * n): for v, w in g[u]: dist[v] = min(dist[v], dist[u] + w) for u in range(2 * n): for v, w in g[u]: if reachable[v] and dist[v] > dist[u] + w: print("inf") exit() print(-dist[-1])