#include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } int main(){ int n, m; cin >> n >> m; vector a(n); rep(i,0,n) cin >> a[i]; vector u(m), v(m); vector c(m); rep(i,0,m){ cin >> u[i] >> v[i]; u[i]--; v[i]--; cin >> c[i]; c[i] -= a[v[i]]; } vector d1(n,1e18); d1[n-1] = 0; rep(i,0,n){ rep(j,0,m){ chmin(d1[u[j]], d1[v[j]]); } } vector d2(n,1e18); d2[0] = 0; bool mode = 1; rep(i,0,n+1){ rep(j,0,m){ if (d1[u[j]] == 0 || d1[v[j]] == 0){ if (chmin(d2[v[j]], d2[u[j]] + c[j]) && i == n){ mode = 0; } } } } if (!mode){ cout << "inf" << '\n'; return 0; } vector d(n,1e18); d[0] = -a[0]; rep(i,0,n){ rep(j,0,m){ chmin(d[v[j]], d[u[j]] + c[j]); } } cout << - d[n-1] << '\n'; }