#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i) #define all(a) (a).begin(),(a).end() const ll INF = 1ll << 60; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int N, M; cin >> N >> M; vector A(N); rep(i, 0, N) cin >> A[i]; vector>> G(N); rep(i, 0, M) { int a, b; ll c; cin >> a >> b >> c; --a, --b; G[a].push_back({b, c - A[b]}); } vector dist(N, INF); dist[0] = -A[0]; rep(t, 0, N - 1) { rep(v, 0, N) { if (dist[v] == INF) continue; for (auto e : G[v]) { dist[e.first] = min(dist[e.first], dist[v] + e.second); } } } ll ans = -dist[N - 1]; rep(t, 0, N) { rep(v, 0, N) { if (dist[v] == INF) continue; for (auto e : G[v]) { if (dist[e.first] > dist[v] + e.second) dist[e.first] = -INF; } } } if (dist[N - 1] == -INF) cout << "inf\n"; else cout << ans << '\n'; }