#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+1); rep(i,m){ ll a,b,w; cin>>a>>b>>w; a--,b--; G[a].push_back(Edge(b,w-A[a])); } G[n-1].push_back(Edge(n,-A[n-1])); bool exist_negative_cycle=false; vector dist(n+1,INF); dist[0]=0; rep(i,n+1){ bool update=false; rep(v,n+1){ 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 && update) exist_negative_cycle=true; } if(exist_negative_cycle) cout<<"inf"<