#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef pair Pii; const ll mod = 998244353; struct Edge { int from, to; ll cost; }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector a(n); for (auto &x: a) cin >> x; vector> edges(n); for (int i = 0; i < m; i++) { int u, v; ll c; cin >> u >> v >> c; u--; v--; edges[u].push_back(Edge({u, v, c - a[v]})); } vector dist(n, 1e18); dist[0] = -a[0]; for (int i = 0; i < n * 2; i++) { for (int j = 0; j < n; j++) { for (auto &e: edges[j]) { if (dist[e.from] + e.cost < dist[e.to]) { dist[e.to] = dist[e.from] + e.cost; } } } } for (int i = 0; i < n; i++) { for (auto &e: edges[i]) { if (dist[e.from] + e.cost < dist[e.to]) { cout << "inf" << endl; return 0; } } } cout << -dist[n - 1] << endl; return 0; }