#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
 
/*---------------------------------------------------*/

struct Edge{
    long long to, cost;
    Edge(long t, long c){
        to = t;
        cost = c;
    }
};

class Bellman_Ford{
    private:
        const long long Inf = 1LL << 50;
        vector<long long> dist;
        vector<vector<Edge> > adj;
    public:
        Bellman_Ford(int v){
            dist = vector<long long>(v + 1);
            adj = vector<vector<Edge> >(v + 1);
        }

        void add_edge(int from, int to, int cost){
            adj[from].push_back(Edge(to, cost));
        }

        bool shortest_path(int s){
            for(int i = 0; i < (int)dist.size(); i++)dist[i] = Inf;
            dist[s] = 0;
            
            int cnt = 0;
            bool update = true;
            while(update){
                if(cnt > (int)dist.size() + 1)return false;
                cnt++;
                update = false;
                for(int i = 0; i < (int)dist.size(); i++){
                    for(int  j = 0; j < (int)adj[i].size(); j++){
                        Edge e = adj[i][j];
                        if(dist[e.to] > dist[i] + e.cost && dist[i] != Inf){
                            dist[e.to] = dist[i] + e.cost;
                            if(cnt == adj.size() - 1 && e.to == adj.size()) return false;
                            update = true;
                        }
                    }
                }
            }
            return true;
        }

        bool shortest_path(int s, int n){
            for(int i = 0; i < (int)dist.size(); i++)dist[i] = Inf;
            dist[s] = 0;
            for(int i = 0; i < (int)dist.size() - 1; i++){
                for(int j = 0; j < (int)adj.size(); j++){
                    for(auto e : adj[j]){
                        if(dist[e.to] > dist[j] + e.cost && dist[j] != Inf){
                            dist[e.to] = dist[j] + e.cost;
                        }
                    }
                }
            }
            ll tmp = dist[n];
            for(int i = 0; i < (int)dist.size() - 1; i++){
                for(int j = 0; j < (int)adj.size(); j++){
                    for(auto e : adj[j]){
                        if(dist[e.to] > dist[j] + e.cost && dist[j] != Inf){
                            dist[e.to] = dist[j] + e.cost;
                        }
                    }
                }
            }
            return tmp == dist[n];
        }

        long long get_distance(int x){
            return dist[x];
        }

        void DEBUG(){
            for(int i = 0; i < (int)dist.size(); i++){
                cout << 1 << " --> " << i << " = " << dist[i] << endl;
            }
        }
};

int main(){
    int n, m, a, b, c;
    cin >> n >> m;
    Bellman_Ford bel(n);
    rep(i,m){
        cin >> a >> b >> c;
        bel.add_edge(a, b, -c);
    }
    
    if(bel.shortest_path(1, n)){
        cout << -bel.get_distance(n) << endl;
    }else{
        cout << "inf" << endl;
    }
    return 0;
}



Measured memory_bytes: 384