#include "bits/stdc++.h"
using namespace std;

//諸機能
#pragma region MACRO 
#define putans(x)  std::cerr << "[ answer ]: " ; cout << (x) << endl
#define dputans(x) std::cerr << "[ answer ]: "; cout << setprecision(40) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,n,a) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,n,0)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define equals(a,b) (fabs((a)-(b)) < EPS)
#ifdef _DEBUG //ファイルからテストデータを読み込む
std::ifstream ifs("data.txt");
#define put ifs >>
#else //ジャッジシステムでいい感じにやる
#define put cin >>
#endif
#pragma endregion
//デバッグなどの支援
#pragma region CODING_SUPPORT
#ifdef _DEBUG
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#else
#define dbg(var0) {}
#define dbg2(var0, var1) {}
#define dbg3(var0, var1, var2) {}
#define dbgArray(a,n) {}
#endif 
#pragma endregion 
//typedef（書き換える、書き足す可能性ある）
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-10)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(2*1e15)
#pragma endregion



struct edge { ll from, to, cost; };
typedef pair<ll, ll> P;

//bellmanFord
ll V;
ll E;
static const ll MAX_V = 1000;
static const ll MAX_E = 2000;
edge es[MAX_E];
ll d[MAX_V];


void bellman_Ford(ll s) {
	for (ll i = 0; i < V; i++) d[i] = INF;
	d[s] = 0;
	while (true) {
		bool update = false;
		for (ll i = 0; i < E; i++) {
			edge e = es[i];
			if (d[e.from] != INF&& d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if (!update) break;
	}
}

bool findNegativeLoop(ll s) {
	for (ll i = 0; i < V; i++) d[i] = INF;
	d[s] = 0;
	for (ll i = 0; i < V; i++) {
		for (ll j = 0; j < E; j++) {
			edge e = es[j];
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				if (i == V - 1) return true;
			}
		}
	}
	return false;
}

void calc() {
	ll v, e; put v >> e;
	V = v;
	E = e;
	rep(i, e) {
		ll to, from, cost;
		put to >> from >> cost;
		es[i] = { from-1,to-1,-cost };
	}
	if (findNegativeLoop(v-1)) {
		cout << "inf" << endl;
		return;
	}
	bellman_Ford(v-1);
	putans(-1 * d[0]);
}

//
//struct edge { ll from, to, cost; };
//typedef pair<ll, ll> P;
//
////bellmanFord
//ll V;
//ll E;
//static const ll MAX_V = 2000;
//static const ll MAX_E = 3000;
//edge es[MAX_E];
//ll d[MAX_V];
//
//
//void bellman_Ford(ll s) {
//	for (ll i = 0; i < V; i++) d[i] = -INF;
//	d[s] = 0;
//	while (true) {
//		bool update = false;
//		for (ll i = 0; i < E; i++) {
//			edge e = es[i];
//			if (d[e.from] != -INF&& d[e.to] < d[e.from] + e.cost) {
//				d[e.to] = d[e.from] + e.cost;
//				update = true;
//			}
//		}
//		if (!update) break;
//	}
//}
//
//bool findPositiveLoop(ll s) {
//	for (ll i = 0; i < V; i++) d[i] = -INF;
//	d[s] = 0;
//	for (ll i = 0; i < V; i++) {
//		for (ll j = 0; j < E; j++) {
//			edge e = es[j];
//			if (d[e.from] != -INF && d[e.to] < d[e.from] + e.cost) {
//				d[e.to] = d[e.from] + e.cost;
//				if (i == V - 1) return true;
//			}
//		}
//	}
//	return false;
//}
//
//void calc() {
//	ll v, e; put v >> e;
//	V = v;
//	E = e;
//	rep(i, e) {
//		ll from, to, cost;
//		put from >> to >> cost;
//		es[i] = { from - 1,to - 1,cost };
//	}
//	if (findPositiveLoop(0)) {
//		cout << "inf" << endl;
//		return;
//	}
//	bellman_Ford(0);
//	putans(d[v - 1]);
//}



int main() {
	calc();
	return 0;
}



Measured memory_bytes: 256