import std.stdio, std.algorithm, std.conv, std.array, std.string, std.typecons;

alias Edge = Tuple!(int, "to", int, "point");
alias Vertex = Tuple!(Edge[], "nexts", long, "max");

auto mk_vs()
{
    Vertex[2000] vs;
    foreach (ref v; vs) v.max = long.min;
    return vs;
}

auto VS = mk_vs();

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];

    foreach (_; 0..M) {
        auto abc = readln.split.to!(int[]);
        VS[abc[0]-1].nexts ~= Edge(abc[1]-1, abc[2]);
    }

    void solve(int c, int i, long p) {
        if (c > 1500) throw new Exception("");
        if (VS[i].max >= p) return;
        VS[i].max = p;
        foreach (e; VS[i].nexts) solve(c+1, e.to, p + e.point);
    }

    try {
        solve(0, 0, 0);
        writeln(VS[N-1].max);
    } catch(Exception _) {
        writeln("inf");
    }
}