#include <bits/stdc++.h>

using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define debug(x) cerr << #x << ":" << x << endl;
#define debug2(x) for(auto a : x) cerr << a << " "; cerr << endl;
#define debug3(x) rep(i, sizeof(x)) cerr << x[i] << " "; cerr << endl;

vector<pii> around = {MP(1, 0), MP(-1, 0), MP(0, 1), MP(0, -1)};

//------------------------------------------------------

template<typename T = ll, typename U = ll> class BellmanFord {
public:

    struct edge {
        T from, to;
        U cost;
    };

    ll V; //頂点数（なくてもよい）
    vector<edge> E;
    map<T, U> d;

    BellmanFord(ll V_num = 200010) : V(V_num) {
    }

    void calc(T s) {
        d.clear();
        rep(i, V + 1) d[i] = LINF;
        d[s] = U(0);
        while (1) {
            bool update = false;
            for (auto e : E) {
                //if (d.find(e.from) == d.end()) d[e.from] = LINF;
                //if (d.find(e.to) == d.end()) d[e.to] = LINF;
                if (d[e.from] != LINF && d[e.to] > d[e.from] + e.cost) {
                    d[e.to] = d[e.from] + e.cost;
                    update = true;
                }
            }
            if (!update) return;
        }
    }

    bool calc_and_find_negative_loop(T s, T g) {
        d.clear();
        map<T, U> negative;
        rep(i, V + 1) d[i] = LINF;
        d[s] = U(0);

        rep(i, V) {
            bool update = false;
            for (auto e : E) {
                //if (d.find(e.from) == d.end()) d[e.from] = LINF;
                //if (d.find(e.to) == d.end()) d[e.to] = LINF;
                if (d[e.from] != LINF && d[e.to] > d[e.from] + e.cost) {
                    d[e.to] = d[e.from] + e.cost;
                    update = true;
                    if (i == V - 1) negative[e.from] = negative[e.to] = true;
                }
            }
            if (!update) return false;
        }
        return negative[g];
    }

    bool find_any_negative_loop() {
        map<T, U> d_;
        rep(i, V) for (auto e : E) {
            if (d_[e.to] > d_[e.from] + e.cost) {
                d_[e.to] = d_[e.from] + e.cost;
                if (i == V - 1) return true;
            }
        }
        return false;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, m;
    cin >> n >> m;
    BellmanFord<> bf(n);

    rep(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        bf.E.push_back({a, b, -c});
    }

    if (bf.calc_and_find_negative_loop(1, n)) cout << "inf" << endl;
    else cout << -bf.d[n] << endl;
    return 0;
}


Measured memory_bytes: 384