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, A[a] - c)) inf = 10 ** 18 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] + c: dist[v] = dist[u] + c for u, v, c in g: if dist[u] != -inf and dist[v] < dist[u] + c: exit(print("inf")) print(dist[N - 1] + A[N - 1])