#include using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; template using V = vector; template using VV = V>; template using VVV = V>; template using VVVV = VV>; #define rep(i,n) for(ll i=0ll;i void chmin(T& t, const U& u) { if (t > u) t = u; } template void chmax(T& t, const U& u) { if (t < u) t = u; } // cin.tie(nullptr); // ios::sync_with_stdio(false); // cout << fixed << setprecision(20); void solve(){ ll n,m; cin >> n >> m; V a(n); rep(i,n) cin >> a[i]; VV> g(n); V x, y, d; rep(i,m){ ll a,b,c; cin >> a >> b >> c; a--; b--; x.eb(a); y.eb(b); d.eb(c); g[b].eb(a, c); } V ok(n, 0); ok[n-1] = 1; queue que; que.push(n-1); while(!que.empty()){ ll nd = que.front(); que.pop(); for(auto[nx, _]:g[nd]) if(!ok[nx]){ ok[nx] = 1; que.push(nx); } } V dist(n, -INF); dist[0] = a[0]; rep(j, n) rep(i, m) chmax(dist[y[i]], dist[x[i]]-d[i]+a[y[i]]); ll ans = dist[n-1]; rep(i, m) if(dist[y[i]] < dist[x[i]]-d[i]+a[y[i]] && ok[y[i]]){ ans = INF; } if(ans == INF) cout << "inf" << endl; else cout << ans << endl; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int t=1; // cin >> t; rep(i,t) solve(); }