#define rep(i,n) for (int i=0;i<(n);i++)
#define repr(i,n) for (int i=(n)-1;i>=0;i--)
#define rep2(i,s,n) for (int i=(s);i<(n);i++)
#define rep2r(i,s,n) for (int i=(n)-1;i>=(s);i--)

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define vs vector<string>
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vd vector<double>
#define vc vector<char>
#define cd complex<double>
#define vcd vector<cd>

#define all(a) (a).begin(),(a).end()
#define range(a,i) (a).begin(),(a).begin()+i
#define repv(itr,v) for(auto itr=(v).begin();itr!=(v).end();itr++)

#define sint(a) int a; scanf("%d",&a);
#define sint2(a,b) int a,b; scanf("%d %d",&a,&b);
#define sint3(a,b,c) int a,b,c; scanf("%d %d %d",&a,&b,&c);
#define sint4(a,b,c,d) int a,b,c,d; scanf("%d %d %d %d",&a,&b,&c,&d);
#define sint5(a,b,c,d,e) int a,b,c,d,e; scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
#define sll(a) ll a; scanf("%lld",&a);
#define sll2(a,b) ll a,b; scanf("%lld %lld",&a,&b);
#define sll3(a,b,c) ll a,b,c; scanf("%lld %lld %lld",&a,&b,&c);
#define sll4(a,b,c,d) ll a,b,c,d; scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
#define sll5(a,b,c,d,e) ll a,b,c,d,e; scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e);
#define svi(v,n) vector<int> v(n); rep(i,n) scanf("%d", &v[i]);
#define svll(v,n) vector<ll> v(n); rep(i,n) scanf("%lld", &v[i]);
#define sdouble(x) double x; scanf("%lf",&x);
#define svd(v,n) vector<double> v(n); rep(i,n) scanf("%lf", &v[i]);
#define schar(x) char x; scanf(" %c", &x);
#define sstring(x) string x; cin >> x;

#define pint(a) printf("%d\n",a);
#define pint2(a,b) printf("%d %d\n",a,b);
#define pint3(a,b,c) printf("%d %d %d\n",a,b,c);

#define pll(a) printf("%lld\n",a);
#define pll2(a,b) printf("%lld %lld\n",a,b);
#define pll3(a,b,c) printf("%lld %lld %lld\n",a,b,c);

#define printvi(v) printf("[ ");repv(itr,v) printf("%d ",*itr);printf("]\n");
#define printvll(v) printf("[ ");repv(itr,v) printf("%lld ",*itr);printf("]\n");

#define ceili(x,y) (x)%(y)?(x)/(y)+1:(x)/(y)

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#else
#pragma GCC diagnostic ignored "-Wunused-result"
#endif

#ifdef _MSC_VER
#define DEBUG
#endif

#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <complex>

using namespace std;




int main(int argc, char** argv) {
	sint2(N, M);
	vector<map<int, int>> G(N);
	rep(i, M) {
		sint3(a, b, c);
		a--; b--;
		G[a][b] = c;
	}
	vll score(N, LLONG_MIN);
	score[0] = 0;
	set<int> route;
	stack<int> pos;
	pos.push(0);
	while (!pos.empty()) {
		int current = pos.top();
		route.insert(current);
#ifdef DEBUG
		pint(current);
#endif
		repv(itr, G[current]) {
			int next = itr->first;
			ll nextScore = (score[current] == LLONG_MAX) ? LLONG_MAX : score[current] + itr->second;
			if (score[next] < nextScore) {
				if (route.find(next) != route.end()) {
					nextScore = LLONG_MAX;
				}
				score[next] = nextScore;
				pos.push(next);
			}
		}
		if (pos.top() == current) {
			pos.pop();
			route.erase(current);
		}
	}
	if (score[N - 1] == LLONG_MAX) {
		printf("inf\n");
	}
	else {
		pll(score[N - 1]);
	}
	return 0;
}

Measured memory_bytes: 384