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;
int[][] abcs;
 
void main(){
    auto nm=readln.split.map!(to!int).array;
    auto N=nm[0];
    auto M=nm[1];
    foreach(i;0..M){
        auto abc=readln.split.map!(to!int).array;
        abc[0]-=1;
        abc[1]-=1;
        abcs~=abc;
    }

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

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

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

bool update(){
    bool updated=false;
    foreach(abc;abcs){
        auto res=scores[abc[0]]+abc[2];
        if(scores[abc[1]]<res){
            updated=true;
            scores[abc[1]]=res;
        }
    }
    return updated;
}
