#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <class... T> void printl(T&&...){ }
template <class... T> void printc(T&&...){ }
template <class... T> void prints(T&&...){ }
template <class... T> void printd(T&&...){ }
template <class... T> void printArr(T&&...){ }
#endif

struct Node{
    vector<int> dests;
    vector<int> cs;
};

struct Edge{
    int from, to, cost;
};

bool bellmanFord(vector<ll>& dists, vector<Edge>& edges, int start = 0){
    int n = dists.size();
    dists[start] = 0;
    for(int i = 0; i < n; i++){
        for(Edge edge : edges){
            if(dists[edge.from] != MLL && dists[edge.from] + edge.cost < dists[edge.to]){
                if(i == n - 1){ return false; }
                dists[edge.to] = dists[edge.from] + edge.cost;
            }
        }
    }
    return true;
}

bool bellmanFord2(vector<ll>& dists, vector<Edge>& edges, int start, vector<ll>& rdists){
    int n = dists.size();
    dists[start] = 0;
    for(int i = 0; i < n; i++){
        for(Edge edge : edges){
            if(dists[edge.from] != MLL && dists[edge.from] + edge.cost < dists[edge.to] && rdists[edge.to] != MLL){
                if(i == n - 1){ return false; }
                dists[edge.to] = dists[edge.from] + edge.cost;
            }
        }
    }
    return true;
}

int main(){
    int n, m;
    cin >> n >> m;
    // vector<Node> nodes(n), rnodes(n);
    vector<Edge> edges, redges;
    for(int i = 0; i < m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--; c = -c;
        edges.push_back({a, b, c});
        redges.push_back({b, a, 1});
        // nodes[a].dests.push_back(b);
        // nodes[a].cs.push_back(c);
        // rnodes[b].dests.push_back(a);
        // rnodes[b].cs.push_back(1);
    }

    vector<ll> dists(n, MLL), rdists(n, MLL);
    bellmanFord(rdists, redges, n - 1);
    if(!bellmanFord2(dists, edges, 0, rdists)){
        cout << "inf" << '\n';
        return 0;
    }

    // vector<ll> rdists(n, MLL);
    // rdists[n - 1] = 0;
    // for(int i = 0; i < n; i++){
    //     for(int j = 0; j < n; j++){
    //         for(uint k = 0; k < rnodes[j].dests.size(); k++){
    //             if(rdists[j] != MLL && rdists[j] + rnodes[j].cs[k] < rdists[rnodes[j].dests[k]]){
    //                 rdists[rnodes[j].dests[k]] = rdists[j] + rnodes[j].cs[k];
    //             }
    //         }
    //     }
    // }
    //
    // vector<ll> dists(n, MLL);
    // dists[0] = 0;
    // for(int i = 0; i < n; i++){
    //     for(int j = 0; j < n; j++){
    //         for(uint k = 0; k < nodes[j].dests.size(); k++){
    //             if(dists[j] != MLL && dists[j] + nodes[j].cs[k] < dists[nodes[j].dests[k]] && rdists[nodes[j].dests[k]] != MLL){
    //                 if(i == n - 1){
    //                     cout << "inf" << '\n';
    //                     return 0;
    //                 }
    //                 dists[nodes[j].dests[k]] = dists[j] + nodes[j].cs[k];
    //             }
    //         }
    //     }
    // }
    cout << - dists[n - 1] << '\n';
    return 0;
}


Measured memory_bytes: 384