#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include using namespace std; const ll INF=1LL<<60; struct Edge{ int to; ll w; Edge(int to,ll w) : to(to),w(w) {} }; using Graph=vector>; template bool chmin(T& a,T b){ if(a>b){ a=b; return true; } else return false; } int main(){ int n,m; cin>>n>>m; vector A(n); rep(i,n) cin>>A[i]; Graph G(n),G1(n); vector AA(m),B(m),C(m); rep(i,m){ ll a,b,w; cin>>a>>b>>w; a--,b--; AA[i]=a,B[i]=b,C[i]=w; G[a].push_back(Edge(b,w-A[a])); } vector can(n); auto dfs=[&](auto dfs,int v,int p)->void{ can[v]=1; for(auto nv:G[v]){ if(nv.to==p) continue; dfs(dfs,nv.to,v); } }; dfs(dfs,n-1,-1); rep(i,m){ if(can[AA[i]]==0 || can[B[i]==0]) continue; G1[AA[i]].push_back(Edge(B[i],C[i]-A[AA[i]])); } bool exist_negative_cycle=false; vector dist(n,INF); dist[0]=0; rep(i,n){ bool update=false; rep(v,n){ if(dist[v]==INF) continue; for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ update=true; } } } if(!update) break; if(i==n-1 && update) exist_negative_cycle=true; } if(exist_negative_cycle) cout<<"inf"<