#include #include using mint = atcoder::modint998244353; using namespace std; using ll = long long; using ld = long double; template using vc = vector; template using vvc = vc>; void solve(); int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ll t = 1; // cin >> t; for (int i = 1; i <= t; i++) solve(); return 0; } #define rep(i, a, b) for (ll i = (a); i < (b); i++) ll dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0}; struct Edge { ll from, to, cost; Edge(ll from, ll to, ll cost) : from(from), to(to), cost(cost) {} }; void solve() { ll n, m; cin >> n >> m; vc A(n); rep(i, 0, n) cin >> A[i]; vc edges; const ll INF = 1LL << 60; auto bell = [&](vc& dist) -> bool { dist[0] = 0; rep(i, 0, n) { bool update = false; for (auto e : edges) { if (dist[e.from] == INF) continue; if (dist[e.to] > dist[e.from] + e.cost) { dist[e.to] = dist[e.from] + e.cost; update = true; } } if (!update) return false; } rep(i, 0, n) { for (auto e : edges) { if (dist[e.from] == INF) continue; if (dist[e.to] > dist[e.from] + e.cost) { dist[e.to] = -INF; } } } return true; }; vc dist(n, INF); rep(i, 0, m) { ll a, b, c; cin >> a >> b >> c; a--, b--; edges.push_back(Edge(a, b, c - A[b])); } bell(dist); if (dist[n - 1] == -INF) { cout << "inf" << endl; return; } cout << A[0] - dist[n - 1] << endl; }