#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, bool> BellmanFord(Graph g, int s) { int n = g.size(), m = g.edgesize(); vector dist(n, 1000000000000000000); bool negacycle = false; dist[s] = 0; 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 (dist[v] > dist[u] + w) { dist[v] = dist[u] + w; if (i == n - 1) { negacycle = true; } } } } return {dist, negacycle}; } 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) { cout << "inf" << endl; } else { cout << -(d[n - 1] - a[0]) << endl; } }