using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, m) = (c[0], c[1]); var a = NList; var map = NArr(m); WriteLine(Play(n, m, a, map)); } static string Play(int n, int m, int[] a, int[][] map) { var tree = new List<(int to, long len)>[n]; for (var i = 0; i < tree.Length; ++i) tree[i] = new List<(int to, long len)>(); var revtree = new List[n]; for (var i = 0; i < revtree.Length; ++i) revtree[i] = new List(); foreach (var edge in map) { tree[edge[0] - 1].Add((edge[1] - 1, a[edge[1] - 1] - edge[2])); revtree[edge[1] - 1].Add(edge[0] - 1); } var reachable = new bool[n]; DFS(n - 1, revtree, reachable); var INF = long.MinValue / 2; var len = Enumerable.Repeat(INF, n).ToArray(); len[0] = a[0]; for (var i = 0; i < n; ++i) { var flg = false; for (var j = 0; j < n; ++j) foreach (var next in tree[j]) { if (len[next.to] < len[j] + next.len) { if (reachable[next.to]) flg = true; len[next.to] = len[j] + next.len; } } if (i + 1 == n && flg) { return "inf"; } } return len[^1].ToString(); } static void DFS(int cur, List[] tree, bool[] reachable) { reachable[cur] = true; foreach (var next in tree[cur]) { if (reachable[next]) continue; DFS(next, tree, reachable); } } }