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); 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)>(); foreach (var edge in map) { tree[edge[0] - 1].Add((edge[1] - 1, edge[2] - a[edge[1] - 1])); } var INF = long.MaxValue / 2; var len = Enumerable.Repeat(INF, n).ToArray(); len[0] = -a[0]; var ans = 0L; var ans2 = 0L; for (var i = 0; i < 2 * n; ++i) { for (var j = 0; j < n; ++j) foreach (var next in tree[j]) len[next.to] = Math.Min(len[next.to], len[j] + next.len); if (i + 1 == n) ans = len[n - 1]; if (i + 1 == 2 * n) ans2 = len[n - 1]; } WriteLine(ans != ans2 ? "inf" : (-ans).ToString()); } }