#include<bits/stdc++.h>
using namespace std;
long n,m,r;
int main(){
	cin>>n>>m;
	vector<long> a(m),b(m),c(m),d(n,-1e18),nc(n,0);
	for(int i=0;i<m;++i){
		cin>>a[i]>>b[i]>>c[i];
		--a[i];--b[i];
	}
	d[0]=0;
	for(int i=0;i<2*n-1;++i)for(int j=0;j<m;++j){
		if(d[a[j]]+c[j]>d[b[j]]){
			if(i>n-2)nc[b[j]]=1;
			d[b[j]]=d[a[j]]+c[j];
		}
		nc[b[j]]|=nc[a[j]];
		if(i==n-2)r=d[n-1];
	}
	nc[n-1]?cout<<"inf":cout<<r;
}