using Training20200530.Questions;
using Training20200530.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Training20200530.Questions.Algorithms;

namespace Training20200530.Questions
{
    /// <summary>
    /// https://atcoder.jp/contests/abc061/tasks/abc061_d
    /// </summary>
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var nm = inputStream.ReadIntArray();
            var nodesCount = nm[0];
            var edgesCount = nm[1];

            var bellmanFord = new BellmanFord<int, WeightedEdge>(Enumerable.Repeat(0, edgesCount)
                                                                           .Select(_ => LoadEdge(inputStream.ReadIntArray())), nodesCount);
            var result = bellmanFord.GetDistancesFrom(0);
            var distances = result.Item1;
            var negativeCycleNodes = result.Item2;
            if (negativeCycleNodes.Contains(nodesCount - 1))
            {
                yield return "inf";
            }
            else
            {
                yield return -distances[nodesCount - 1];
            }
        }

        WeightedEdge LoadEdge(int[] input)
        {
            var a = input[0] - 1;
            var b = input[1] - 1;
            var c = -input[2];
            return new WeightedEdge(a, b, c);
        }
    }

    public interface IEdge<TNode>
    {
        TNode From { get; }
        TNode To { get; }
    }

    public interface IWeightedEdge<TNode> : IEdge<TNode>
    {
        int Weight { get; }
    }

    public interface IGraph<TNode, TEdge> where TEdge : IEdge<TNode>
    {
        IEnumerable<TEdge> this[TNode node] { get; }
        IEnumerable<TEdge> Edges { get; }
        IEnumerable<TNode> Nodes { get; }
        int NodeCount { get; }
    }

    [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Auto)]
    public struct WeightedEdge : IWeightedEdge<int>
    {
        public int From { get; }
        public int To { get; }
        public int Weight { get; }

        public WeightedEdge(int from, int to) : this(from, to, 1) { }

        public WeightedEdge(int from, int to, int weight)
        {
            From = from;
            To = to;
            Weight = weight;
        }

        public override string ToString() => $"{From}--[{Weight}]-->{To}";
    }

    public class WeightedGraph : IGraph<int, WeightedEdge>
    {
        private readonly List<WeightedEdge>[] _edges;
        public IEnumerable<WeightedEdge> this[int node] => _edges[node];
        public IEnumerable<WeightedEdge> Edges => Nodes.SelectMany(node => this[node]);
        public IEnumerable<int> Nodes => Enumerable.Range(0, NodeCount);
        public int NodeCount { get; }

        public WeightedGraph(int nodeCount) : this(nodeCount, Enumerable.Empty<WeightedEdge>()) { }

        public WeightedGraph(int nodeCount, IEnumerable<WeightedEdge> edges)
        {
            _edges = Enumerable.Repeat(0, nodeCount).Select(_ => new List<WeightedEdge>()).ToArray();
            NodeCount = nodeCount;
            foreach (var edge in edges)
            {
                AddEdge(edge);
            }
        }

        public WeightedGraph(int nodeCount, IEnumerable<IEnumerable<int>> distances)
        {
            _edges = new List<WeightedEdge>[nodeCount];

            int i = 0;
            foreach (var row in distances)
            {
                _edges[i] = new List<WeightedEdge>(nodeCount);
                int j = 0;
                foreach (var distance in row)
                {
                    _edges[i].Add(new WeightedEdge(i, j++, distance));
                }
                i++;
            }
        }

        public void AddEdge(WeightedEdge edge) => _edges[edge.From].Add(edge);
    }

    namespace Algorithms
    {
        public class BellmanFord<TNode, TEdge> where TEdge : IWeightedEdge<TNode>
        {
            protected readonly List<TEdge> _edges;
            protected readonly int _nodeCount;

            public BellmanFord(IGraph<TNode, TEdge> graph) : this(graph.Edges, graph.NodeCount) { }

            public BellmanFord(IEnumerable<TEdge> edges, int nodeCount)
            {
                _edges = edges.ToList();
                _nodeCount = nodeCount;
            }

            public Tuple<Dictionary<TNode, long>, HashSet<TNode>> GetDistancesFrom(TNode startNode)
            {
                var distances = new Dictionary<TNode, long>(_nodeCount);
                var negativeCycleNodes = new HashSet<TNode>();
                distances[startNode] = 0;

                for (int i = 1; i < 2 * _nodeCount; i++)
                {
                    foreach (var edge in _edges)
                    {
                        // そもそも出発点に未到達なら無視
                        long originDistance;
                        if (distances.TryGetValue(edge.From, out originDistance))
                        {
                            var newCost = originDistance + edge.Weight;
                            long destinationDistance;
                            if (!distances.TryGetValue(edge.To, out destinationDistance) || destinationDistance > newCost)
                            {
                                distances[edge.To] = newCost;
                                if (i >= _nodeCount)
                                {
                                    negativeCycleNodes.Add(edge.To);
                                }
                            }
                        }
                    }
                }

                foreach (var negativeCycleNode in negativeCycleNodes)
                {
                    distances[negativeCycleNode] = long.MinValue;
                }

                return new Tuple<Dictionary<TNode, long>, HashSet<TNode>>(distances, negativeCycleNodes);
            }
        }
    }

}


namespace Training20200530
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Training20200530.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Training20200530.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13652