#include <bits/stdc++.h> 

using namespace std;

#define fcout(d) cout << fixed << setprecision(d)
#define repU(i,s,t) for(int i = (s); i <= (t); ++i)
#define repD(i,t,s) for(int i = (t); i >= (s); --i)
#define rep(i,n) repU(i,0,n - 1)
#define rep1(i,n) repU(i,1,n)
#define all(v) begin(v),end(v)
#define l_bnd lower_bound
#define u_bnd upper_bound
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define q_ceil(n,d) ((n - 1) / (d) + 1)
#define parity(a,b) (((a)^(b)) & 1 ^ 1)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;

const pair<int,int> DIR[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int INF_32 = (1 << 30) - 1;
const ll INF_64 = (1LL << 62) - 1;
const int MOD = 1e9 + 7;

template<class Abel> struct D_Graph {
	int V,E;
	Abel INF;
	vector<vector<pair<int,Abel>>> adj;
	vector<vector<pair<int,Abel>>> adj_inv;
	
	D_Graph(int V_size = 0, Abel dist_max = INF_32) : INF(dist_max)
	{
		init(V_size);
	}
	
	void init(int V_size) {
		V = V_size, E = 0;
		adj.clear(); 
		adj_inv.clear();
		adj.resize(V + 1);
		adj_inv.resize(V + 1);
		adj[0].resize(V);
		for(int i = 1; i <= V; ++i){
			adj[0][i - 1] = {i,0};
			adj[i].reserve(min(V,100));
			adj_inv[i].reserve(min(V,100));
		}
	}
	
	int deg_out(int v) { return adj[v].size(); }
	
	int deg_in(int v) { return adj_inv[v].size(); }
	
	bool is_leaf(int v) { return deg_out(v) == 0; }
	
	bool is_root(int v) { return deg_in(v) == 0; }
	
	void add_edge(int from, int to, Abel cost = 1) {
		adj[from].push_back({to,cost});
		adj_inv[to].push_back({from,cost});
		++E;
	}
	
	void sort_adj() {
		for(int i = 0; i <= V; ++i) sort_adj(i);
	}
	
	void sort_adj(int v) {
		sort(begin(adj[v]),end(adj[v]));
		sort(begin(adj_inv[v]),end(adj_inv[v]));
	}
	
	void dijkstra(vector<Abel> &dist, int src) {
		dist.clear();
		dist.assign(V + 1,INF);
		priority_queue<pair<Abel,int>,vector<pair<Abel,int>>,greater<pair<Abel,int>>> que;
		que.push({0,src});
		while(!que.empty()){
			int d = que.top().first;
			int v = que.top().second;
			que.pop();
			if(dist[v] <= d) continue;
			dist[v] = d;
			for(auto e : adj[v]) que.push({e.second + d,e.first});
		}
	}
	
	bool is_cyclic() {
		vector<int> s;
		return !tsort(s);
	}
	
	bool tsort(vector<int> &seq, bool idx_ord = 0) {
		seq.clear();
		seq.reserve(V + 1);
		sort_adj();
		vector<int> in(V + 1);
		for(int i = 0; i <= V; ++i) in[i] = deg_in(i);
		stack<int> rt;
		rt.push(0);
		while(!rt.empty()){
			int r = rt.top();
			rt.pop();
			for(auto e : adj[r]){
				int v = e.first;
				if(r) --in[v];
				if(!in[v]){
					rt.push(v);
					if(idx_ord){
						auto pos = begin(seq);
						bool det = 0;
						for(auto i = begin(seq); i < end(seq); ++i){
							if(!det && v > *i) ++pos;
							else det = 1; 
							auto u = lower_bound(begin(adj[*i]),end(adj[*i]),make_pair(v,-INF));
							if(u < end(adj[*i]) && u->first == v){
								pos = i + 1;
								det = 0;
							}
						}
						seq.insert(pos,v);
					}else{
						seq.push_back(v);
					}
				}
			}
		}
		if(seq.size() == V) return 1;
		return 0;
	}
	
	void scc(vector<int> &label) {
		label.assign(V + 1,0);
		stack<int> s;
		vector<int> low(V + 1);
		vector<int> idx(V + 1,0);
		int l = 0,c = 0;
		dfs(0,c,l,s,label,low,idx);
	}
	
	void dfs(int v, int &cnt, int &l, stack<int> &s, vector<int> &label, vector<int> &low, vector<int> &idx) {
		s.push(v);
		idx[v] = low[v] = cnt++;
		for(auto e : adj[v]){
			int u = e.first;
			if(label[u]) continue;
			if(!idx[u]) dfs(u,cnt,l,s,label,low,idx);
			low[v] = min(low[v],low[u]);
		}
		if(idx[v] == low[v]){
			++l;
			for(int t = 0; t != v; s.pop()){
				t = s.top();
				label[t] = l;
			}
		}
	}
};

int n,m;
ll dist[1010];
bool vis[1010] = {};
bool lop[1010] = {};
bool rchabl[1010] = {};

bool Dfs(D_Graph<ll> &G, ll scr, int v){
	vis[v] = 1;
	bool rch = v == n;
	for(auto i : G.adj[v]){
		if(dist[i.fir] < dist[v] + i.sec){
			if(vis[i.fir]) lop[i.fir] = 1;
			else{
				dist[i.fir] = dist[v] + i.sec;
				rch |= Dfs(G,dist[i.fir],i.fir);
			}
		}
	}
	vis[v] = 0;
	return rchabl[v] = rch;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n >> m;
	D_Graph<ll> G(n); 
	rep(i,m){
		int a,b,c;
		cin >> a >> b >> c;
		G.add_edge(a,b,c);
	}
	fill(all(dist),-INF_64);
	dist[1] = 0;
	Dfs(G,0,1);
	rep1(i,n){
		if(lop[i] & rchabl[i]){
			cout << "inf\n";
			return 0;
		}
	}
	cout << dist[n] << endl;
}





Measured memory_bytes: 3584