// #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; #include using namespace atcoder; #include #include #include using namespace __gnu_pbds; #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define FOR(i, start, end) for (int i = start; i < (int)(end); ++i) #define RFOR(i, rstart, rend) for (int i = rstart; i >= (int)(rend); --i) #define REP(i, end) FOR(i, 0, end) #define BIT(x, i) (((x)>>(i))&1) using ll = long long; using ull = unsigned long long; using pii = pair; using pll = pair; constexpr ll LINF = 1LL << 60; constexpr int INF = 1 << 30; template using Graph = vector>; template using TREE = tree, rb_tree_tag, tree_order_statistics_node_update>; template using PQ = priority_queue, greater>; void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";} templatevoid chmax(T &a, const T &b) { if (avoid chmin(T &a, const T &b) { if (b istream &operator>>(istream&is,vector&v){for(T &in:v){is>>in;}return is;} template ostream &operator<<(ostream&os,const vector&v){for(auto it=v.begin();it!=v.end();){os<<*it<<((++it)!=v.end()?" ":"\n");}return os;} /* 回文判定 */ bool isPalindrome(const string &s){int sz=s.size(); REP(i,sz/2){if(s[i]!=s[sz-1-i])return false;} return true;} /* 座標圧縮 */ template vector compress(const vector&A){vector ret(A.size()); auto tmp = A; sort(ALL(tmp)); tmp.erase(unique(ALL(tmp)), tmp.end()); REP(i,A.size()) ret[i] = lower_bound(ALL(tmp), A[i]) - tmp.begin(); return ret;} /* 約数列挙 整数nの約数のvectorを返す */ vector enumdiv(ll n){vectors; for(ll i = 1;i*i<=n;i++){if(n%i==0){s.push_back(i);if(i*i!=n)s.push_back(n/i);}}return s;} /* 素因数分解 pair<素数、指数>のvectorを返す */ vector primeDecomposition(ll x){vector ret;ll tmp=x;for(ll i=2;i*i<=x;++i){if(tmp%i==0){ll cnt=0; while(tmp%i==0){tmp/=i;++cnt;}ret.emplace_back(i,cnt);}}if(tmp!=1)ret.emplace_back(tmp,1);return ret;} /* エラトステネスの篩 n未満の素数を列挙。isprimeには素数かどうかが入っている */ vector isprime;vector era(int n) {isprime.resize(n, true);vector res;isprime[0] = false; isprime[1] = false;for (int i = 2; i < n; ++i){if (isprime[i]) {res.push_back(i);for (int j = i*2; j < n; j += i) isprime[j] = false;}}return res;} /* トポロジカルソート */ vector topo_sort(const Graph &G){int n = G.size();vector deg(n), ret;for(const auto &v:G)for(const auto &to:v) ++deg[to];queue que;REP(i,n) if(deg[i]==0)que.push(i);while(!que.empty()){const int from = que.front();que.pop();ret.push_back(from);for(const auto &to:G[from])if(--deg[to]==0) que.push(to);}return ret;}; using mint = modint998244353; // using mint = modint; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,m; cin >> n >> m; vector a(n); cin >> a; Graph G(n); vector deg(n); REP(i,m){ int u,v,c; cin >> u >> v >> c; --u; --v; G[u].emplace_back(v,c); ++deg[v]; } REP(i,n){ sort(ALL(G[i]), [&](const pll &x, const pll &y){return a[x.first]-x.second > a[y.first]-y.second;}); } vector dp(n, -LINF); dp[0] = a[0]; queue que; REP(i,n) if(deg[i]==0) que.push(i); while(!que.empty()){ const int from = que.front(); que.pop(); for(auto [to, cost]: G[from]){ if(dp[from] != -LINF) chmax(dp[to], dp[from] + a[to] - cost); if(--deg[to]==0) que.push(to); } } if(dp[n-1] != -LINF){ cout << dp[n-1] << endl; return 0; } vector seen(n,false),finished(n,false); auto dfs = [&](auto &&f, int now) -> void { seen[now] = true; for(auto [to, cost]: G[now]){ if(finished[to]) continue; if(seen[to]){ if(dp[to] < dp[now] + a[to] - cost){ cout << "inf" << endl; exit(0); } continue; } if(dp[to] <= dp[now] + a[to] - cost){ dp[to] = dp[now] + a[to] - cost; f(f, to); } } seen[now] = false; finished[now] = true; }; dfs(dfs, 0); cout << dp[n-1] << endl; return 0; }