using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("3 3");
            WillReturn.Add("1 2 4");
            WillReturn.Add("2 3 3");
            WillReturn.Add("1 3 5");
            //7
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2 2");
            WillReturn.Add("1 2 1");
            WillReturn.Add("2 1 1");
            //inf
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("6 5");
            WillReturn.Add("1 2 -1000000000");
            WillReturn.Add("2 3 -1000000000");
            WillReturn.Add("3 4 -1000000000");
            WillReturn.Add("4 5 -1000000000");
            WillReturn.Add("5 6 -1000000000");
            //-5000000000
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    struct GraphInfoDef
    {
        internal int FromPos;
        internal int ToPos;
        internal int Kyori;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] wkArr = { };
        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();

        SplitAct(InputList[0]);
        int N = wkArr[0];

        var GraphInfoList = new List<GraphInfoDef>();
        foreach (string EachStr in InputList.Skip(1)) {
            SplitAct(EachStr);

            GraphInfoDef WillAdd;
            WillAdd.FromPos = wkArr[0];
            WillAdd.ToPos = wkArr[1];
            WillAdd.Kyori = wkArr[2];
            GraphInfoList.Add(WillAdd);
        }
        GraphInfoList.Sort((A, B) => A.FromPos.CompareTo(B.FromPos));
        var StaIndDict = new Dictionary<int, int>();
        for (int I = 0; I <= GraphInfoList.Count - 1; I++) {
            int wkFromPos=GraphInfoList[I].FromPos;
            if (StaIndDict.ContainsKey(wkFromPos) == false) {
                StaIndDict[wkFromPos] = I;
            }
        }

        //各ノードまでの距離のDict
        var SumKyoriDict = new Dictionary<int, long>();
        SumKyoriDict.Add(1, 0);

        //ベルマンフォード法で解く
        long Cost1 = 0;
        long Cost2 = 0;
        for (int I = 1; I <= 2 * N - 1; I++) {
            foreach (int EachKey in SumKyoriDict.Keys.ToArray()) {
                //そのノードから訪問可能なノードで
                //最短距離を更新可能なら更新
                if (StaIndDict.ContainsKey(EachKey) == false) continue;
                int StaInd = StaIndDict[EachKey];

                for (int J = StaInd; J <= GraphInfoList.Count - 1; J++) {
                    if (GraphInfoList[J].FromPos != EachKey) break;

                    long wkSumKyori = SumKyoriDict[EachKey] + GraphInfoList[J].Kyori;
                    if (SumKyoriDict.ContainsKey(GraphInfoList[J].ToPos))
                        if (wkSumKyori <= SumKyoriDict[GraphInfoList[J].ToPos])
                                continue;
                    SumKyoriDict[GraphInfoList[J].ToPos] = wkSumKyori;
                }

                //List<GraphInfoDef> wkGraphList =
                //    GraphInfoList.FindAll(X => X.FromPos == EachKey);
                //foreach (GraphInfoDef EachGraphInfo in wkGraphList) {
                //    long wkSumKyori = SumKyoriDict[EachKey] + EachGraphInfo.Kyori;
                //    if (SumKyoriDict.ContainsKey(EachGraphInfo.ToPos))
                //        if (wkSumKyori <= SumKyoriDict[EachGraphInfo.ToPos])
                //            continue;
                //    SumKyoriDict[EachGraphInfo.ToPos] = wkSumKyori;
                //}
            }
            if (I == N - 1) Cost1 = SumKyoriDict[N];
            if (I == 2 * N - 1) Cost2 = SumKyoriDict[N];
        }
        if (Cost1 < Cost2) Console.WriteLine("inf");
        else Console.WriteLine(Cost1);
    }
}


Measured memory_bytes: 19936