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

class Program
{
    private static readonly Scanner sc = new Scanner();
    static void Main(string[] args)
    {
        int n = sc.Int;
        int m = sc.Int;

        BellmanFord bf = new BellmanFord(n);

        for (int i = 0; i < m; i++)
            bf.AddEdge(sc.Int-1, sc.Int-1, -sc.Int);

        bf.CalcDistance(0);

        Console.WriteLine(bf.IsNegInf(n-1) ? "inf" : (-bf.GetDistance(n-1)).ToString());
    }
}

class Scanner
{
    private string[] _str = new string[0];
    private int _i;

    public string Line { get { return Console.ReadLine(); } }

    public string Str
    {
        get
        {
            if (_i >= _str.Length)
            {
                _str = Line.Split(' ');
                _i = 0;
            }
            return _str[_i++];
        }
    }

    public string[] StrArr { get { return Line.Split(' '); } }
    public int Int { get { return int.Parse(Str); } }
    public int[] IntArr { get { return Line.Split(' ').Select(int.Parse).ToArray(); } }
    public long Long { get { return long.Parse(Str); } }
    public long[] LongArr { get { return Line.Split(' ').Select(long.Parse).ToArray(); } }
    public double Double { get { return double.Parse(Str); } }
    public double[] DoubleArr { get { return Line.Split(' ').Select(double.Parse).ToArray(); } }
}



class BellmanFord
{
    private class Edge
    {
        public int To;
        public long Cost;
    }

    private readonly int _n;
    private readonly List<Edge>[] _g;
    private readonly long[] _dist;
    private readonly bool[] _negloop;
    private readonly bool[] _visited;

    public bool NegLoopExist;

    public BellmanFord(int n)
    {
        _n = n;
        _g = new List<Edge>[n];
        _dist = new long[n];
        _negloop = new bool[n];
        _visited = new bool[n];

        for (var i = 0; i < n; i++)
            _g[i] = new List<Edge>();
    }

    public void AddEdge(int from, int to, int cost)
    {
        _g[from].Add(new Edge {To = to, Cost = cost});
    }

    public void CalcDistance(int s)
    {
        for (var i = 0; i < _n; i++)
        {
            _dist[i] = long.MaxValue;
            _visited[i] = false;
            _negloop[i] = false;
        }
        _dist[s] = 0;

        var q = new Queue<int>();
        var qn = new Queue<int>();
        bool[] enqueued = new bool[_n];
        q.Enqueue(s);
        var cnt = 0;

        while (q.Count != 0 && cnt < _n * 2)
        {
            var update = false;
            while (q.Count != 0)
            {
                var v = q.Dequeue();
                enqueued[v] = false;
                _visited[v] = true;
                foreach (var e in _g[v])
                {
                    var newdist = _dist[v] + e.Cost;
                    if (_dist[e.To] > newdist)
                    {
                        _dist[e.To] = newdist;
                        if (!enqueued[e.To])
                            qn.Enqueue(e.To);
                        enqueued[e.To] = true;
                        update = true;

                        if (cnt >= _n - 1)
                            _negloop[v] = _negloop[e.To] = true;
                    }
                }
            }
            q = new Queue<int>(qn);
            qn.Clear();
            if (update)
                cnt++;
        }

        if (cnt >= _n)
            NegLoopExist = true;
    }

    public long GetDistance(int i)
    {
        return _dist[i];
    }

    public bool IsNegInf(int i)
    {
        return _negloop[i];
    }

    public bool IsReachable(int i)
    {
        return _visited[i];
    }
}

Measured memory_bytes: 17588