#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 d(n,1e18); d[0] = -a[0]; ll memo1 = 0; ll memo2 = 0; rep(i,0,4*m+1){ rep(j,0,m){ chmin(d[v[j]], d[u[j]] + c[j]); } if (i == 2*m){ memo1 = d[n-1]; }else if(i == 4*m){ memo2 = d[n-1]; } } if (memo1 > memo2){ cout << "inf" << '\n'; }else{ cout << -memo2 << '\n'; } }