# oj t -c "python3 main.py" import sys,math from collections import defaultdict,deque from itertools import combinations,permutations,accumulate,product from bisect import bisect,bisect_left,bisect_right from heapq import heappop,heappush,heapify #from sortedcontainers import SortedList,SortedSet def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def ms(): return map(int, input().split()) def li(): return list(map(int,input().split())) inf = pow(10,18) #//////////////////////////////////// N,M = ms() A = [-1]+li() G = [set() for _ in range(N+1)] for _ in range(M): u,v,c = ms() G[u].add((v,c)) H = [] heappush(H,(-A[1],1)) visited = [False]*(N+1) while H: c,v = heappop(H) if visited[v]: continue c *= -1 if v==N: print(c) exit() visited[v] = True for v2,c2 in G[v]: if A[v2]c2 and visited[v2]: print('inf') exit() if visited[v2] and A[v2]!=c2: continue heappush(H,(-(c+A[v2]-c2),v2))