#include <bits/stdc++.h>
using namespace std;

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
typedef pair<ll,ll> RR;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

//グラフ処理クラス

template<class T,class Compare = less<T>>
class warshall_floyd{
private:
    int node_num;
    vector<vector<int>> pred;
    vector<vector<T>> c_ab;
    T Ls,Gt;
    bool is_negative;
public:
    warshall_floyd(int node_num) : 
        node_num(node_num),
        pred(node_num+1,vector<int>(node_num+1,INT_MAX)),
        c_ab(node_num,vector<T>(node_num)),
        is_negative(false)
        {
            if(Compare()(0,1)) Ls=std::numeric_limits<T>::lowest(),Gt=std::numeric_limits<T>::max();
            else Ls=std::numeric_limits<T>::max(),Gt=std::numeric_limits<T>::lowest();
            rep(i,node_num) c_ab[i].assign(node_num,Gt);
            rep(i,node_num) pred[i][i]=-1,c_ab[i][i]=0;
        }
    void direct(int from,int to,T cost){
        c_ab[from][to]=cost;
        pred[from][to]=from;
    }
    void calc(void){
        rep(rel,node_num)rep(a,node_num){
            rep(b,node_num){
                if(c_ab[a][rel]==Gt||c_ab[rel][b]==Gt)continue;
                T nc=c_ab[a][rel]+c_ab[rel][b];
                if(Compare()(nc,c_ab[a][b])){
                    c_ab[a][b]=nc;
                    pred[a][b]=pred[rel][b];
                }
            }
        }
        rep(i,node_num) is_negative=is_negative||(c_ab[i][i]!=0);
    }
    T get_cost(int idx_start,int idx_end) const{
        return c_ab[idx_start][idx_end];
    }
    bool has_negative_cycle() const{
        return is_negative;
    }
    bool is_negative_path(int idx_start,int idx_end){
        int node=idx_end;
        if( pred[idx_start][idx_end]==INT_MAX) return false;
        while(c_ab[node][node]==0 &&//負閉路でない
            pred[idx_start][node]<INT_MAX&&//始点から辿れる
            pred[idx_start][node]!=-1){//始点でない
                node=pred[idx_start][node];
            }
        return (c_ab[node][node]!=0);
    }
    vector<int> get_min_path(int idx_start,int idx_end)const{
        int node=idx_end;
        vector<int> vec;
        vec.push_back(node);
        while(c_ab[node][node]==0 &&//負閉路でない
            pred[idx_start][node]<INT_MAX&&//始点から辿れる
            pred[idx_start][node]!=-1){//始点でない
                node=pred[idx_start][node];
                vec.push_back(node);
            }
        return vec;
    }

};

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    int N,M;
    cin >>N>>M;

    warshall_floyd<ll,greater<ll>> X(N);
    int a,b,c;
    rep(i,M){
        cin >> a>>b>>c;
        X.direct(a-1,b-1,c);
    }
    X.calc();

    if(X.is_negative_path(0,N-1)){
        cout<<"inf"<<endl;
    }else{
        cout<<X.get_cost(0,N-1)<<endl;
    }
    return (0);
}

Measured memory_bytes: 14080