#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
//#include <cassert>
#include <vector>
//#include <array>
//#include <set>
//#include <map>
//#include <unordered_set>
#include <unordered_map>
//#include <stack>
#include <queue>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i, n) for (int i = 1; i <= (int)(n); i++)
using ll = long long;
using namespace std;

#include <vector>

using Weight = long long;

struct Vertex;
using Vertices = std::vector<Vertex *>;
struct Edge;
using Edges = std::vector<const Edge *>;

struct Vertex {
	const int id;
	Edges edges;
	Vertex(int id);
	void add_edge(const Edge *const p_e);
	void add_edge(const Edges &es);
};

struct Edge {
	Vertex *p_src, *p_dst;
	Weight weight;
	
	Edge(Vertex *p_src, Vertex *p_dst, Weight weight);
	Edge(const Edge &e);
	Edge& operator = (const Edge &de);
};

struct Graph {
	Vertices vertices;
	Edges edges;
	Graph(int nvertices);
	~Graph();
	void add_edge(Edge *p_edge);
	void add_edge(int edge_src, int edge_dst, Weight w);
	//void copy_vertex(int id_original, int id_copy);
};

Vertex::Vertex(int id) : id(id) { }
void Vertex::add_edge(const Edge *const p_e) {
	edges.push_back(p_e);
}
void Vertex::add_edge(const Edges &es) {
	for (const auto &p_e : es) {
		add_edge(p_e);
	}
}

//----------------------------------------------------------

using namespace std;

Edge::Edge(Vertex *p_src, Vertex *p_dst, Weight weight) : p_src(p_src), p_dst(p_dst), weight(weight) { }
Edge::Edge(const Edge &e) : Edge(e.p_src, e.p_dst, e.weight) {}
Edge& Edge::operator = (const Edge &e) {
	p_src = e.p_src;
	p_dst = e.p_dst;
	weight = e.weight;
	return *this;
}
bool operator < (const Edge &e1, const Edge &e2) {
	return e1.weight != e2.weight ? e1.weight > e2.weight : // !!INVERSE!!
		e1.p_src != e2.p_src ? e1.p_src->id < e2.p_src->id : e1.p_dst->id < e2.p_dst->id;
}

Graph::Graph(int nvertices) {
	for (int id = 0; id < nvertices; id++) {
		vertices.push_back(new Vertex(id));
	}
}
Graph::~Graph() {
	for (auto &p_vertex : vertices) {
		delete p_vertex;
	}
	for (auto &p_edge : edges) {
		delete p_edge;
	}
}
void Graph::add_edge(Edge *p_edge) {
	(*vertices[p_edge->p_src->id]).add_edge(p_edge);
	edges.push_back(p_edge);
}
void Graph::add_edge(int edge_src, int edge_dst, Weight w) {
	add_edge(new Edge(vertices[edge_src], vertices[edge_dst], w));
}
//void Graph::copy_vertex(int id_original, int id_copy) {
//	vertices[id_copy]->add_edge(vertices[id_original]->edges);
//}


std::vector<Weight> dijkstra(const Graph &g, const int id_start, const Weight INF);
std::vector<Weight> bellman_ford(const Graph &g, const int id_start, const Weight INF);

//----------------------------------------------------------
#include <queue>


vector<Weight> dijkstra(const Graph &g, const int id_start, const Weight INF) { // INFに気を付けよ
	using Pwi = pair<Weight, int>;

	const size_t n = g.vertices.size();
	vector<Weight> d(n, INF);
	vector<bool> is_used(n, false);
	priority_queue<Pwi, vector<Pwi>, greater<Pwi>> que;

	d[id_start] = 0;
	for (que.push(Pwi(0, id_start)); !que.empty(); ) {
		Pwi p = que.top(); que.pop();
		const int tmpid = p.second; // p.first >= d[tmpid]
		if (is_used[tmpid]) continue;
		is_used[tmpid] = true;
		//assert(p.first == d[tmpid]);
		for (const auto &p_nxte : g.vertices[tmpid]->edges) {
			const int nxtid = p_nxte->p_dst->id;
			Weight nxtd = d[tmpid] + p_nxte->weight;
			if (d[nxtid] > nxtd) {
				d[nxtid] = nxtd;
				que.push(Pwi(nxtd, nxtid));
			}
		}
	}
	return d;
}

vector<Weight> bellman_ford(const Graph &g, const int id_start, const Weight INF) {
	// INFに気を付けよ d_max < INF
	// 負の閉路からアクセスできる頂点にはd = -INF
	const size_t n = g.vertices.size();
	vector<Weight> d(n, INF);
	d[id_start] = 0;
	bool is_negative_cycle = false;
	for (size_t i = 1; i <= n; i++)
	{
		for (const auto &tmpe : g.edges) {
			const int id_src = tmpe->p_src->id;
			const int id_dst = tmpe->p_dst->id;
			if (d[id_src] != INF && d[id_dst] > d[id_src] + tmpe->weight) {
				d[id_dst] = d[id_src] + tmpe->weight;
				if (i == n) {
					d[id_dst] = -INF;
					is_negative_cycle = true;
				}
			}
		}
	}
	if (is_negative_cycle) {
		for (size_t i = 1; i < n; i++)
		{
			for (const auto &tmpe : g.edges) {
				const int id_src = tmpe->p_src->id;
				const int id_dst = tmpe->p_dst->id;
				if (d[id_src] == -INF && d[id_dst] != -INF) {
					d[id_dst] = -INF;
				}
			}
		}
	}
	return d;
}

void solve() {
	const Weight INF = (ll)1e13;
	int N, M;
	cin >> N >> M;
	Graph g(N+1);
	REP(i, M) {
		int a, b; Weight c;
		cin >> a >> b >> c;
		g.add_edge(a, b, -c);
	}

	Weight dN = -bellman_ford(g, 1, INF)[N];
	if (dN != INF) {
		cout << dN << endl;
	}
	else {
		cout << "inf" << endl;
	}
	return;
}

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

Measured memory_bytes: 384