#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,m=map(int,input().split())\n"
"e=[]\n"
"for _ in range(m):\n"
"    a,b,c=map(int,input().split())\n"
"    e.append([a-1,b-1,-c])\n"
"M=10**18\n"
"d=[0]+[M]*~-n\n"
"k=0\n"
"v=0\n"
"while k<n*2:\n"
"    k+=1\n"
"    if k==n:v=d[-1]\n"
"    f=0\n"
"    for a,b,c in e:\n"
"        if d[b]>d[a]+c:\n"
"            d[b]=d[a]+c\n"
"            f=1\n"
"    if not f:\n"
"        break\n"
"if not v or v==d[-1]:\n"
"    print(-d[-1])\n"
"else:\n"
"    print('inf')\n"
"\"";
  system(s);
  return 0;
}            