n, m = map(int, input().split()) a = list(map(int, input().split())) g = [[] for _ in range(2 * n)] for i in range(n): g[i].append((i + n, -a[i])) for _ in range(m): a, b, c = map(int, input().split()) a -= 1 b -= 1 g[a + n].append((b, c)) 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 _ in range(2 * n): for u in range(2 * n): for v, w in g[u]: if v == 2 * n - 1 and dist[v] > dist[u] + w: print("inf") exit() dist[v] = min(dist[v], dist[u] + w) print(-dist[-1])