import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
import core.bitop;

T RD(T = long)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool INSIDE(T)(T x, T b, T e) { return x >= b && x < e; }

long mod = pow(10, 9) + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

struct UnionFind
{
	void init(long n) { par = new long[](n); foreach (i; 0..n) par[i] = i; }
	long root(long i) { return par[i] == i ? i : (par[i] = root(par[i])); }
	bool same(long i, long j) { return root(i) == root(j); }
	void unite(long i, long j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; }
	long[] par;
}

long[] dijkstra(long from, long to, long[][] edges)
{
	long[] path;
	auto cost = new long[](edges.length); fill(cost, long.max); cost[from] = 0;
	long[][] open = [[from]];
	while (!open.empty)
	{
		auto n = open.front; open.popFront;
		auto p = n[0];
		foreach (i; 0..edges.length)
		{
			if (edges[p][i] == -1) continue;
			auto c = cost[p] + edges[p][i];
			if (c < cost[to] && c < cost[i]) { cost[i] = c; if (i == to) path = i ~ n; else open ~= i ~ n; }
		}
	}
	return cost[to] ~ path;
}

void main()
{
	auto N = RD;
	auto M = RD;

	auto v = new long[2][][](N+1);
	foreach (i; 0..M)
	{
		auto a = RD;
		auto b = RD;
		auto c = RD;
		v[a]  ~= [b, c];
	}

	auto memo = new long[][](N+1);
	auto inf  = new bool[](N+1);
	long[] f(long[2][] path)
	{
		auto pos = path[$-1][0];
		foreach (i, e; path[0..$-1])
		{
			if (e[0] == pos)
			{
				long s;
				foreach (ee; path[i..$])
					s += ee[1];
				if (s > 0)
				{
					inf[e[0]] = true;
					return [long.min+1];
				}
				else return [long.min];
			}
		}
		
		long[] r = pos == N ? [0L] : [long.min];
		bool isInf;
		foreach (e; v[pos])
		{
			auto b = e[0];
			auto c = e[1];
			long[] tmp;
			if (memo[b].length == 0)
			{
				tmp = f(path ~ e);
				memo[b] = tmp;
			}
			else
				tmp = memo[b];

			if (tmp[0] == long.min+1)
				isInf = true;
			else if (tmp[0] == long.max)
				tmp = [long.max] ~ pos ~ tmp[1..$];
			else if (tmp[0] != long.min)
				tmp = [tmp[0]+c] ~ pos ~ tmp[1..$];
			r = r[0] > tmp[0] ? r : tmp;
		}
		if (isInf)
			return r[0] > long.min+1 ? long.max ~ r[1..$] : long.min ~ r[1..$];
		else
			return r;
	}
	
	auto r = f([[1, 0]]);
	/*bool isInf;
	foreach (e; r[1..$])
	{
		isInf |= inf[e];
	}*/
	writeln(r[0] == long.max ? "inf" : to!string(r[0]));
	stdout.flush();
}