#include using namespace std; #include using namespace atcoder; using ll = long long; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; using VD = vector; using VVD = vector; using VS = vector; using P = pair; using VP = vector

; #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define out(x) cout << x << endl #define dout(x) cout << fixed << setprecision(10) << x << endl #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define sz(x) (int)(x.size()) #define re0 return 0 #define pcnt __builtin_popcountll template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr int inf = 1e9; constexpr ll INF = 1e18; //using mint = modint1000000007; using mint = modint998244353; int di[4] = {1,0,-1,0}; int dj[4] = {0,1,0,-1}; struct Edge{ int to; ll w; Edge(int to,ll w):to(to),w(w) {} }; int main(){ ll n,m; cin >> n >> m; VL a(n); rep(i,n) cin >> a[i]; vector> g(n); vector> g2(n); rep(i,m){ ll u,v,c; cin >> u >> v >> c; u--,v--; g[u].emplace_back(v,c-a[v]); g2[v].emplace_back(u,c-a[v]); } auto bfs0 = [&](ll s){ VL res(n); res[s] = 1; queue q; q.emplace(s); while(sz(q)){ ll v = q.front(); q.pop(); for(auto e:g[v]){ if(res[e.to]) continue; res[e.to] = 1; q.emplace(e.to); } } return res; }; auto bfs1 = [&](ll s){ VL res(n); res[s] = 1; queue q; q.emplace(s); while(sz(q)){ ll v = q.front(); q.pop(); for(auto e:g2[v]){ if(res[e.to]) continue; res[e.to] = 1; q.emplace(e.to); } } return res; }; VL dist0 = bfs0(0); VL dist1 = bfs1(n-1); set need; rep(i,n){ if(dist0[i]==0) continue; if(dist1[i]==0) continue; need.insert(i); } bool exist_negative_cycle = false; vector dist(n,INF); dist[0] = 0; for(int iter = 0;iter < n;iter++){ bool update = false; for(int v = 0;v < n;v++){ if(dist[v] == INF) continue; for(auto e:g[v]){ if(!need.count(e.to)) continue; if(chmin(dist[e.to],dist[v]+e.w)){ update = true; } } } if(!update) break; if(iter == n-1 && update) exist_negative_cycle = true; } if(exist_negative_cycle) cout << "inf" << endl; else { ll ans = -dist[n-1]; ans += a[0]; out(ans); } }