#include using namespace std; struct Edge { Edge() {} 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; }; struct Graph { private: int n, m; bool dir; vector> g; vector e; public: Graph() {} Graph(int n_, bool dir_) : n(n_), m(0), dir(dir_), g(n), e(0) {} Graph(int n_) : n(n_), m(0), dir(false), g(n), e(0) {} int size() { return n; } int edgesize() { return m; } bool directed() { return dir; } void add(int u, int v, long long w) { g[u].emplace_back(u, v, w, m); e.emplace_back(u, v, w, m); if (!dir) { g[v].emplace_back(v, u, w, m); } m++; } vector operator[](int v) { return g[v]; } Edge edge(int i) { return e[i]; } }; pair, vector> BellmanFord(Graph g, int s) { int n = g.size(), m = g.edgesize(); long long INF = 1000000000000000000; vector dist(n, INF); vector nega(n, false); dist[s] = 0; for (int i = 0; i < n - 1; i++) { for (int j = 0; j < m; j++) { auto e = g.edge(j); int u = e.from, v = e.to; long long w = e.cost; if (dist[u] != INF && dist[v] > dist[u] + w) { dist[v] = dist[u] + w; } } } vector d2 = dist; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { auto e = g.edge(j); int u = e.from, v = e.to; long long w = e.cost; if (d2[u] != INF && d2[v] > d2[u] + w) { d2[v] = d2[u] + w; nega[v] = true; } if (nega[u]) { nega[v] = true; } } } return {dist, nega}; } 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, true); for (int i = 0; i < m; i++) { int u, v; lint w; cin >> u >> v >> w; u--; v--; g.add(u, v, w - a[v]); } auto [d, f] = BellmanFord(g, 0); if (f[n - 1]) { cout << "inf" << endl; } else { cout << -(d[n - 1] - a[0]) << endl; } }