import heapq def main(): # アルゴリズム一覧を見る # 嘘解法ですか n, m = map(int, input().split()) vec = list(map(int, input().split())) lst = [] for _ in range(m): a, b, c = map(int, input().split()) a -= 1 b -= 1 lst.append((a, b, c - vec[a])) lst.append((n - 1, n, -vec[n - 1])) dist = [float('inf')] * (n + 1) dist[0] = 0 cnt = 0 while cnt < n + 10: end = True for a, b, c in lst: if dist[a] != float('inf') and dist[a] + c < dist[b]: dist[b] = dist[a] + c end = False if end: break cnt += 1 if cnt == n + 10: print("inf") else: print(-dist[n]) if __name__ == "__main__": main()