import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial, std.numeric;

long[] scores;
long[][] abcs;
int N;

bool[] updated;

void main(){
    auto nm=readln.split.map!(to!int).array;
    N=nm[0];
    auto M=nm[1];
    foreach(i;0..M){
        auto abc=readln.split.map!(to!long).array;
        abc[0]-=1;
        abc[1]-=1;
        abcs~=abc;
    }

    scores.length=N;
    updated.length=N;
    foreach(ref s;scores[1..$])s=long.min;

    foreach(i;0..N)update();

    foreach(ref u;updated)u=false;

    foreach(i;0..N)update();

    if(updated[N-1]) writeln("inf");
    else writeln(scores[N-1]);
}

void update(){
    foreach(abc;abcs){
        if(scores[cast(uint)abc[0]]==long.min)continue;
        if(updated[cast(uint)abc[0]]){updated[cast(uint)abc[1]]=true;}
        auto res=scores[cast(uint)abc[0]]+abc[2];
        if(scores[cast(uint)abc[1]]<res){
            scores[cast(uint)abc[1]]=res;
            updated[cast(uint)abc[1]]=true;
        }
    }
}
