/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF 1e+18
#define MAX_V 100100
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Graph Start
struct edge {
    int from, to;
    long long cost;
};
/// Graph End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

#define int long long

class DirectedGraph {
    struct edge {
        int from;
        int to;
        int cost;
    };

    int edge_num = 0;

  public:
    int V;
    int E;
    vector<edge> edges;

    DirectedGraph(int v, int e) : V(v), edges(e), E(e){};

    void add_edge(int from, int to, int cost) {
        edge e = {from, to, cost};
        edges[edge_num++] = e;
    }

    // O(E * V)
    vector<int> bellman_ford(int s) {
        vector<int> d(V, INF);
        d[s] = 0;
        for(int i=0;i<V;i++){
            for (int j = 0; j < E; j++) {
                edge e = edges[j];
                if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
                    d[e.to] = d[e.from] + e.cost;
                }
            }
        }

        return move(d);
    }

    bool find_negative_loop(int s) {
        vector<int> d(V, INF);
        d[s] = 0;
        for (int i = 0; i < V*2; i++) {
            for (int j = 0; j < E; j++) {
                edge e = edges[j];
                if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
                    d[e.to] = d[e.from] + e.cost;
                    if (i >= V - 1 && e.to == V-1)
                        return true;
                }
            }
        }

        return false;
    }
};

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cinii(N, M);
    DirectedGraph g = DirectedGraph(N, M);
    rep(i, M) {
        int a,b,c;
        cin >> a >> b >> c;
        g.add_edge(--a, --b, -c);
    }
    if (g.find_negative_loop(0)) {
        cout << "inf" << nn;
        return 0;
    }
    vector<int> d = g.bellman_ford(0);
    cout << -d[N - 1] << nn;
    return 0;
}

Measured memory_bytes: 256