#include using namespace std; struct Edge { Edge() {} Edge(int to_, long long cost_) : to(to_), cost(cost_) {} Edge(int from_, int to_, long long cost_) : from(from_), to(to_), cost(cost_) {} Edge(int from_, int to_, long long cost_, int idx_) : from(from_), to(to_), cost(cost_), idx(idx_) {} int from, to; long long cost; int idx; }; using Graph = vector>; #define add emplace_back vector BellmanFord(Graph g, int s) { int n = g.size(); long long INF = 1000000000000000000; vector dist(n, INF); vector nega(n, false); dist[s] = 0; for (int step = 0; step < n - 1; step++) { bool update = false; for (int u = 0; u < n; u++) { if (dist[u] == INF) { continue; } for (auto e : g[u]) { int v = e.to; long long w = e.cost; if (dist[v] > dist[u] + w) { dist[v] = dist[u] + w; update = true; } } } if (!update) { break; } } for (int step = 0; step < n; step++) { for (int u = 0; u < n; u++) { if (dist[u] == INF) { continue; } for (auto e : g[u]) { int v = e.to; long long w = e.cost; if (dist[v] > dist[u] + w) { dist[v] = dist[u] + w; nega[v] = true; } if (nega[u]) { nega[v] = true; } } } } for (int v = 0; v < n; v++) { if (nega[v]) { dist[v] = -INF; } } return dist; } using lint = long long; int main() { int n, m; cin >> n >> m; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } Graph g(n); for (int i = 0; i < m; i++) { int u, v; lint w; cin >> u >> v >> w; u--; v--; g[u].add(v, w - a[v]); } auto d = BellmanFord(g, 0); if (d[n - 1] == -1000000000000000000) { cout << "inf" << endl; } else { cout << -(d[n - 1] - a[0]) << endl; } }