#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; VI A(n); rep(i, n) cin >> A[i]; vector> to(n + 1); rep(_, m) { int a, b, c; cin >> a >> b >> c; a--, b--; to[a].emplace_back(b, c - A[a]); } to[n - 1].emplace_back(n, -A[n - 1]); constexpr long long INF = 1002003004005006007; n++; VL dist(n, INF); dist[0] = 0; rep(_, n) { rep(u, n) if (dist[u] != INF) for (auto [v, c] : to[u]) chmin(dist[v], dist[u] + c); } VL dist_pre = dist; rep(_, n) { rep(u, n) if (dist[u] != INF) for (auto [v, c] : to[u]) chmin(dist[v], dist[u] + c); } rep(u, n) if (dist[u] < dist_pre[u]) dist[u] = -INF; rep(_, n) { rep(u, n) if (dist[u] == -INF) for (auto [v, c] : to[u]) dist[v] = -INF; } if (dist[n - 1] == -INF) cout << "inf" << '\n'; else cout << -dist[n - 1] << '\n'; }