import std.stdio, std.conv;

struct edge {
        long from, to, cost;
}
edge edges[];
long d[];
long n, m;

long mINF;

void shortest_path(long s) {
        d.length = n;
        for (long i = 0; i < n; i++) {
                d[i] = mINF;
        }

        d[s] = 0;
        while (true) {
                bool update = false;
                for (long i = 0; i < m; i++) {
                        edge e = edges[i];
                        if (d[e.from] != mINF && d[e.to] < d[e.from] + e.cost) {
                                d[e.to] = d[e.from] + e.cost;
                                update =true;
                        }
                }
                if (!update) {
                        break;
                }
        }
}

bool find_negative_loop() {
        d.length = n;
        for (long i = 0; i < n; i++) {
                d[i] = mINF;
        }

        for (long i = 0; i < n; i++) {
                for (long j = 0; j < m; j++) {
                        edge e = edges[j];
                        if (d[e.to] < d[e.from] + e.cost) {
                                d[e.to] = d[e.from] + e.cost;

                                if (i == m-1) return true;
                        }
                }
        }
        return false;

}

void main()
{

        mINF = long.min;

        scanf("%ld %ld", &n, &m);


        for (long i = 0; i < m; i++) {
                long a, b, c;
                scanf("%ld %ld %ld", &a, &b, &c);

                edges ~= edge(a-1, b-1, c);
        }

        if (find_negative_loop()) {
                writeln("inf");
                return;
        }

        shortest_path(0);
        writeln(d[n-1]);

}