import heapq def solve(n, m, a, uvw): graph = [[] for _ in range(n)] for ui, vi, wi in uvw: graph[ui-1].append((vi - 1, wi)) pq = [(-a[0], 0)] mn = [10 ** 18] * n mn[0] = -a[0] while True: cost, node = heapq.heappop(pq) if node == n - 1: return -cost if mn[node] < cost: continue if cost < mn[node]: return "inf" for next_node, next_cost in graph[node]: if a[next_node] <= -cost - next_cost: continue a[next_node] = -cost + next_cost heapq.heappush(pq, (-a[next_node], next_node)) n, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] uvw = [[int(x) for x in input().split()] for _ in range(m)] print(solve(n, m, a, uvw))