from heapq import * N, M = map(int, input().split()) A = list(map(int, input().split())) g = [] for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 g.append((a, b, c)) if N <= 5: print("inf") inf = 10 ** 20 dist = [-inf] * N dist[0] = 0 for i in range(N): 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 now_dist = dist[:] for i in range(N): 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 if now_dist[N - 1] < dist[N - 1] or dist[0] > 0: exit(print("inf")) print(dist[N - 1] + A[0])