#include <bits/stdc++.h>
using namespace std;

class Graph
{
  public:
    struct Edge
    {
        long long to;
        long long distance;
        bool operator<(const Edge &e)
        {
            return distance < e.distance;
        }
        bool operator>(const Edge &e)
        {
            return distance > e.distance;
        }
    };
    vector<vector<long long>> adjacency_matrix;
    long long node;
    vector<list<Edge>> edge;

    Graph(long long N)
    {
        node = N + 1;
        initializeEdgeList();
    }

    void initializeAdjacencyMatrix(long long init)
    {
        adjacency_matrix = vector<vector<long long>>(node, vector<long long>(node, init));
    }

    void initializeEdgeList()
    {
        edge = vector<list<Edge>>(node);
    }

    void updateAdjacencyMatrix(long long from, long long to, long long distance)
    {
        adjacency_matrix[from][to] = distance;
    }

    void addEdge(long long from, long long to, long long distance)
    {
        edge[from].push_back({to, distance});
    }

    // O(V^3)
    // CAUTION: Use adjacency matrix
    void runFloydWarshall()
    {
        for (int i = 0; i < node; i++)
        {
            for (int j = 0; j < node; j++)
            {
                for (int k = 0; k < node; k++)
                {
                    adjacency_matrix[j][k] = min(
                        adjacency_matrix[j][k], adjacency_matrix[j][i] + adjacency_matrix[i][k]);
                }
            }
        }
    }

    // O(VE)
    vector<long long> runBellmanFord(long long from, long long init)
    {
        vector<long long> distance(node, init);
        vector<long long> predecessor(node, -1);
        distance[from] = 0;

        for (long long i = 0; i < node - 1; i++)
        {
            for (long long j = 1; j < node; j++)
            {
                for (auto itr = edge[j].begin(); itr != edge[j].end(); itr++)
                {
                    if (distance[itr->to] > distance[j] + itr->distance)
                    {
                        distance[itr->to] = distance[j] + itr->distance;
                        predecessor[itr->to] = j;
                    }
                }
            }
        }

        for (long long i = 1; i < node; i++)
        {
            for (auto itr = edge[i].begin(); itr != edge[i].end(); itr++)
            {
                if (distance[itr->to] > distance[i] + itr->distance)
                {
                    distance[0]--;
                }
            }
        }
        return distance;
    }

    // O(E + VlogV)
    // CAUTION: Use edge list
    vector<long long> runDijkstra(long long from, long long init)
    {
        vector<list<Edge>> edge_copy = edge;
        vector<long long> distance(node, init);
        distance[from] = 0;

        priority_queue<pair<long long, long long>> queue;
        for (auto itr = edge_copy[from].begin(); itr != edge_copy[from].end(); itr++)
        {
            queue.push(make_pair(itr->distance, itr->to));
            edge_copy[from].erase(itr);
            itr--;
        }

        while (!queue.empty())
        {
            long long d = queue.top().first;
            long long to = queue.top().second;
            queue.pop();
            if (distance[to] == init)
            {
                distance[to] = d;
                for (auto itr = edge_copy[to].begin(); itr != edge_copy[to].end(); itr++)
                {
                    if (distance[itr->to] == init)
                    {
                        queue.push(make_pair(itr->distance + d, itr->to));
                        edge_copy[to].erase(itr);
                        itr--;
                    }
                }
            }
        }

        return distance;
    }

    long long runModifiedBellmanFord(long long from, long long init)
    {
        vector<long long> distance(node, init);
        vector<long long> predecessor(node, -1);
        distance[from] = 0;

        for (long long i = 0; i < node - 1; i++)
        {
            for (long long j = 1; j < node; j++)
            {
                for (auto itr = edge[j].begin(); itr != edge[j].end(); itr++)
                {
                    if (distance[itr->to] > distance[j] + itr->distance)
                    {
                        distance[itr->to] = distance[j] + itr->distance;
                        predecessor[itr->to] = j;
                    }
                }
            }
        }

        vector<bool> is_updated(node, false);
        for (long long i = 0; i < node; i++)
        {
            for (long long j = 1; j < node; j++)
            {
                for (auto itr = edge[j].begin(); itr != edge[j].end(); itr++)
                {
                    if (distance[itr->to] > distance[j] + itr->distance)
                    {
                        distance[itr->to] = distance[j] + itr->distance;
                        is_updated[itr->to] = true;
                    }
                    if (is_updated[j])
                    {
                        is_updated[itr->to] = true;
                    }
                }
            }
        }

        if (is_updated.back())
        {
            return LONG_LONG_MAX;
        }
        else
        {
            return -distance.back();
        }
    }
};

int main()
{
    long long N, M;
    cin >> N >> M;

    Graph g(N);
    long long a, b, c;
    for (long long i = 0; i < M; i++)
    {
        cin >> a >> b >> c;
        g.addEdge(a, b, -c);
    }
    long long ans = g.runModifiedBellmanFord(1, 1LL << 50);
    if (ans == LONG_LONG_MAX)
    {
        cout << "inf" << endl;
    }
    else
    {
        cout << ans << endl;
    }
}


Measured memory_bytes: 384