#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;

int N, M, a[2000], b[2000], c[2000];
ll g[1000], res;

int main() {
	cin >> N >> M;
	for (int i = 0; i != M; ++i) {
		cin >> a[i] >> b[i] >> c[i];
		--a[i];
		--b[i];
	}
	for (int i = 1; i != N; ++i)
		g[i] = -0xe869120e869120;
	for (int i = 0; i != N; ++i) {
		for (int j = 0; j != M; ++j) {
			g[b[j]] = max(g[b[j]], g[a[j]] + c[j]);
		}
	}
	res = g[N - 1];
	for (int i = 0; i != N; ++i) {
		for (int j = 0; j != M; ++j) {
			g[b[j]] = max(g[b[j]], g[a[j]] + c[j]);
		}
	}
	if (g[N - 1] > res)
		cout << "inf" << endl;
	else
		cout << res << endl;
	return 0;
}