#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) void solve() { ll n, m; cin >> n >> m; vector a(n); rep(i, n) cin >> a[i]; vector g(n, vector>()); vector r(n, vector()); rep(i, m) { ll u, v, c; cin >> u >> v >> c, u--, v--; g[u].emplace_back(v, c); r[v].push_back(u); } vector vis1(n, false), vis2(n, false); { vis1[0] = vis2[n - 1] = true; auto dfs1 = [&](auto self, ll u, ll p) -> void { for (const auto &[v, c] : g[u]) { if (v == p || vis1[v]) continue; vis1[v] = true; self(self, v, u); } }; auto dfs2 = [&](auto self, ll u, ll p) -> void { for (const auto v : r[u]) { if (v == p || vis2[v]) continue; vis2[v] = true; self(self, v, u); } }; dfs1(dfs1, 0, -1); dfs2(dfs2, n - 1, -1); } vector score(n, 0); bool updated = true; ll update_count = 0; while (updated) { updated = false; update_count += 1; if (update_count > n + 5) { cout << "inf\n"; return; } vector nex = score; rep(u, n) if (vis1[u] && vis2[u]) { for (const auto &[v, c] : g[u]) if (vis1[v] && vis2[v]) { ll now = score[u] - a[u] + c; if (now < nex[v]) { updated = true; nex[v] = now; } } } score = nex; } cout << -(score[n - 1] - a[n - 1]) << '\n'; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); int T = 1; for (int t = 0; t < T; t++) { solve(); } return 0; }