#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N, M;
    cin>>N>>M;
    vector<int> a(M);
    vector<int> b(M);
    vector<long long> c(M);
    for (int i=0; i<M; i++)
        cin>>a[i]>>b[i]>>c[i],
        a[i]--, b[i]--;

    long long oo = 0x1000000000000000LL;
    vector<long long> d(N, -oo);
    d[0] = 0LL;
    long long d1, d2;
    for (int i=0; i<2*N; i++)
    {
        for (int j=0; j<M; j++)
            d[b[j]] = max(d[b[j]], d[a[j]] + c[j]);
        if (i==N-1)
            d1 = d[N-1];
        if (i==2*N-1)
            d2 = d[N-1];
    }
    if (d1 == d2)
        cout<<d1<<endl;
    else
        cout<<"inf"<<endl;
}
