#include // clang-format off using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair; const ll INF=4e18; void print0(){}; template void print0(H h,T... t){cout<void print1(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print1(t...);} void ioinit() { cout<> edgmap(2502); vector edges; // 各ノードからゴール(n-1)に到達できるか判定 vector arrive(2502); vector search_arrive(2502); bool dfs_arrive(ll u) { if (u == n - 1) { return true; } if (search_arrive[u]) { return false; } search_arrive[u] = true; for (auto e : edgmap[u]) { if (dfs_arrive(e.v)) { return true; } } return false; } // s->各頂点の最長路 vector bf_max(ll s) { vector dp(n, -INF); dp[s] = 0; for (ll op = 0; true; op++) { if (op > n) { return vector(); } bool updated = false; for (auto e : edges) { if (!arrive[e.u] || !arrive[e.v]) continue; // ゴール(n-1)に到達できないノードは無視する if (dp[e.u] != -INF && dp[e.v] < dp[e.u] + e.c) { updated = true; dp[e.v] = dp[e.u] + e.c; } } if (!updated) break; } return dp; } int main() { ioinit(); ll m; cin >> n >> m; vector a(n); for (ll i = 0; i < n; i++) { cin >> a[i]; } for (ll e = 0; e < m; e++) { ll u, v, c; cin >> u >> v >> c; u--; v--; ll score = -c + a[v]; edg ed = {e, u, v, score}; edges.push_back(ed); edgmap[u].push_back(ed); } for (ll i = 0; i < n; i++) { search_arrive.resize(0); search_arrive.resize(n + 1); arrive[i] = dfs_arrive(i); } auto result = bf_max(0); if (result.size() == 0) { print1("inf"); } else { print1(result[n - 1] + a[0]); } return 0; }