#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { int n, m; cin >> n >> m; vector a(n); rep(i, n) cin >> a[i]; vector Edges(m, tuple()); for (auto&& [from, to, cost] : Edges) cin >> from >> to >> cost, --from, --to; constexpr ll INF = 1e18; vector dist(n, INF); dist[0] = -a[0]; rep(i, n - 1) { for (auto&& [from, to, _cost] : Edges) { ll cost = _cost - a[to]; if (dist[to] > dist[from] + cost) { dist[to] = dist[from] + cost; } } } for (auto&& [from, to, _cost] : Edges) { ll cost = _cost - a[to]; if (dist[to] > dist[from] + cost) { cout << "inf" << endl; return 0; } } cout << -dist[n - 1] << endl; return 0; }