#include <iostream>                                                                                                                                                                                         
                                                                                                                                                                                                            
using namespace std;                                                                                                                                                                                        
                                                                                                                                                                                                            
typedef long long ll;                                                                                                                                                                                       
const int MAX_N = 1000;                                                                                                                                                                                     
const int MAX_M = 2000;                                                                                                                                                                                     
//#define INF 999999999                                                                                                                                                                                     
const ll INF = 1LL << 50;                                                                                                                                                                                   
                                                                                                                                                                                                            
int main(){                                                                                                                                                                                                 
    int N, M;                                                                                                                                                                                               
    cin >> N >> M;                                                                                                                                                                                          
                                                                                                                                                                                                            
    int a[MAX_M],b[MAX_M];                                                                                                                                                                                  
    ll c[MAX_M];                                                                                                                                                                                            
    for(int i=0;i<M;i++){                                                                                                                                                                                   
        cin >> a[i] >> b[i] >> c[i];                                                                                                                                                                        
        c[i] = -c[i];                                                                                                                                                                                       
    }                                                                                                                                                                                                       
                                                                                                                                                                                                            
    ll dist[MAX_N];                                                                                                                                                                                         
    for(int i=0; i<N; i++){                                                                                                                                                                                 
        dist[i] = INF;                                                                                                                                                                                      
    }                                                                                                                                                                                                       
    dist[0] = 0;                                                                                                                                                                                            
                                                                                                                                                                                                            
    for(int i=0;i<N-1;i++){                                                                                                                                                                                 
        for(int j=0;j<M;j++){                                                                                                                                                                               
            if(dist[a[j]-1]==INF) continue;                                                                                                                                                                 
            if(dist[b[j]-1] > dist[a[j]-1] + c[j]){                                                                                                                                                         
                dist[b[j]-1] = dist[a[j]-1] + c[j];                                                                                                                                                         
            }                                                                                                                                                                                               
        }                                                                                                                                                                                                   
    }                                                                                                                                                                                                       
                                                                                                                                                                                                            
    ll ans = dist[N-1]; 
    bool neg[MAX_N];                                                                                                                                                                                        
    for(int i=0;i<N;i++) neg[i] = false;                                                                                                                                                                    
                                                                                                                                                                                                            
    for(int i=0;i<N-1;i++){                                                                                                                                                                                 
        for(int j=0;j<M;j++){                                                                                                                                                                               
            if(dist[a[j]-1]==INF) continue;                                                                                                                                                                 
            if(dist[b[j]-1] > dist[a[j]-1] + c[j]){                                                                                                                                                         
                dist[b[j]-1] = dist[a[j]-1] + c[j];                                                                                                                                                         
                neg[b[j]-1] = true;                                                                                                                                                                         
            }                                                                                                                                                                                               
            if(neg[a[j]-1] == true){                                                                                                                                                                        
                neg[b[j]-1] = true;                                                                                                                                                                         
            }                                                                                                                                                                                               
        }                                                                                                                                                                                                   
    }                                                                                                                                                                                                       
                                                                                                                                                                                                            
    if(neg[N-1]==true){                                                                                                                                                                                     
        cout << "inf" << endl;                                                                                                                                                                              
    }else{                                                                                                                                                                                                  
        cout << -ans << endl;                                                                                                                                                                               
    }                                                                                                                                                                                                       
                                                                                                                                                                                                            
    return 0;                                                                                                                                                                                               
}   

Measured memory_bytes: 256