#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
/* -- template -- */

struct UnionFind {
    vector<int> par;
    vector<ll> siz;
    UnionFind(int N) : par(N), siz(N, 1LL) {
        for(int i = 0; i < N; ++i) {
            par[i] = i;
        }
    }
    int root(int x) {
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        siz[ry] += siz[rx];
        par[rx] = ry;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    ll size(int x) {
        return siz[root(x)];
    }
};

int main() {
    int N, M; cin >> N >> M;
    vector<vector<pair<int, ll>>> G(N);
    rep(i, M){
        int a, b, c; cin >> a >> b >> c;
        --a, --b;
        G[a].pb(mp(b, -c));
    }
    vector<ll> d(N, LLINF);
    d[0] = 0;
    for(int i = 0;i < N; ++i) {
        queue<int> Q;
        Q.push(i);
        int loopCount = 0;
        bool flg = false;
        while(!Q.empty()) {
            int q = Q.front();Q.pop();
            if(loopCount > 2 * M && q == N - 1 && flg) {
                cout << "inf" << endl;
                return 0;
            }else if(loopCount > 3 * M) {
                break;
            }
            if(loopCount > M - 1)flg = false;
            ++loopCount;
            for(auto next : G[q]) {
                if(d[next.first] > d[q] + next.second) {
                    d[next.first] = d[q] + next.second;
                    flg = true;
                }
                Q.push(next.first);
            }
        }
    }
    cout << d[N - 1] * -1LL << endl;
}


Measured memory_bytes: 384