#include #include #define rep(i,a,n) for(ll i = a; i < n; i++) #define yes (cout << "Yes" << endl) #define YES (cout << "YES" << endl) #define no (cout << "No" << endl) #define NO (cout << "NO" << endl) #define pb push_back #define pf push_front #define mp make_pair #define fi first #define se second #define all(a) (a).begin(),(a).end() using namespace std; using namespace atcoder; using ll = long long; using ull = unsigned long long; using vi = vector; using vd = vector; using vs = vector; using vl = vector; using vvi = vector>; using Graph = vector>; const int mod = 998244353; const int MOD = 1000000007; const int dx[4] = {-1,0,1,0}; const int dy[4] = {0,1,0,-1}; ll chmin(ll a,ll b) { if(a < b) return a; else return b; } void O(vector v) { rep(i,0,v.size()) { cout << v[i] << " "; } cout << endl; } void O(vector v) { rep(i,0,v.size()) cout << v[i] << endl; cout << endl; } void O(int a) { cout << a << endl; } void O(ll a) { cout << a << endl; } void O(string s) { cout << s << endl; } struct unionfind { vector data; unionfind(int size) : data(size, -1) { } bool unite(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool same(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; ll gcd(ll a, ll b) { a = abs(a); b = abs(b); if (a < b)swap(a, b); while (b) { ll r = a % b; a = b; b = r; } return a; } //x,yがax+by=gcd(a,b)の解になる x,yが格納 ll extgcd(ll a, ll b, ll& x, ll& y) { ll d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } ll pow(ll a,ll b) { ll ans = 1; rep(i,0,b) ans *= a; return ans; } int cnt = 0; int n,m; int a[200007]; ll dp[200005]; void dfs(const vector>> &G,ll t) { for(auto p : G[t]) { ll k = p.fi; ll k2 = p.se; ll ori = dp[k]; dp[k] = dp[t] - k2; if(ori == 0) dfs(G,k); if(1 <= ori && ori < dp[k]) { cout << "inf" << endl; cnt = 1; break; } } } int main() { cin >> n >> m; rep(i,0,n) cin >> a[i]; rep(i,0,n) dp[i] = 0; vector>> G(n); rep(i,0,m) { int p,q,r; cin >> p >> q >> r; p--; q--; G[p].pb(mp(q,r)); } dfs(G,0); if(cnt == 1) return 0; else { cout << dp[n - 1] << endl; } }