#include <algorithm>
#include <bits/stdc++.h>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <limits>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// lib/bellman_ford.hpp
#ifndef BELLMAN_FORD_HPP
#define BELLMAN_FORD_HPP


/*
usage:

tools::bellman_ford<std::int_fast64_t> bf(node_count);
bf.add_edge(from_node, to_node, cost);
const tools::bellman_ford<std::int_fast64_t>::result result = bf.calc(start_node);
for (const std::int_fast64_t& distance : result.distances) {
  // ...
}
*/

namespace tools {
  template <typename T>
  class bellman_ford {
  private:
    class edge {
    public:
      std::size_t from;
      std::size_t to;
      T distance;
      edge(const std::size_t from, const std::size_t to, const T distance) :
        from(from),
        to(to),
        distance(distance) {
      }
    };

    std::size_t m_node_count;
    std::vector<edge> edges;

    static T safe_sum(const T x, const T y) {
      if (x == NEG_INF && y == POS_INF) {
        throw std::runtime_error("indefinite.");
      }
      if (x == NEG_INF) return NEG_INF;
      if (x == POS_INF) return POS_INF;
      if (y == NEG_INF) return NEG_INF;
      if (y == POS_INF) return POS_INF;
      return x + y;
    }

  public:
    static constexpr T POS_INF = std::numeric_limits<T>::max();
    static constexpr T NEG_INF = std::numeric_limits<T>::min();
    static constexpr std::size_t NONE = std::numeric_limits<std::size_t>::max();

    class result {
    public:
      std::vector<T> distances;
      std::vector<std::size_t> prev_nodes;
      result(const std::size_t node_count) :
        distances(node_count, POS_INF),
        prev_nodes(node_count, NONE) {
      }
    };

    bellman_ford(const std::size_t node_count) :
      m_node_count(node_count),
      edges() {
    }

    std::size_t node_count() const {
      return this->m_node_count;
    }

    void add_edge(const std::size_t from, const std::size_t to, const T distance) {
      this->edges.emplace_back(from, to, distance);
    }

    result calc(const std::size_t start_node) const {
      assert(start_node < this->m_node_count);
      result result(this->m_node_count);
      result.distances[start_node] = 0;
      for (std::size_t i = 0; i < this->m_node_count - 1; ++i) {
        for (const edge& edge : this->edges) {
          if (safe_sum(result.distances[edge.from], edge.distance) < result.distances[edge.to]) {
            result.distances[edge.to] = safe_sum(result.distances[edge.from], edge.distance);
            result.prev_nodes[edge.to] = edge.from;
          }
        }
      }
      for (const edge& edge : this->edges) {
        if (safe_sum(result.distances[edge.from], edge.distance) < result.distances[edge.to]) {
          result.distances[edge.to] = NEG_INF;
          result.prev_nodes[edge.to] = edge.from;
        }
      }
      for (std::size_t i = 0; i < this->m_node_count; ++i) {
        for (const edge& edge : this->edges) {
          if (safe_sum(result.distances[edge.from], edge.distance) < result.distances[edge.to]) {
            result.distances[edge.to] = safe_sum(result.distances[edge.from], edge.distance);
            result.prev_nodes[edge.to] = edge.from;
          }
        }
      }
      return result;
    }
  };
}

#endif

// main.cpp

int main() {
  i64 N, M;
  std::cin >> N >> M;

  tools::bellman_ford<i64> bf(N);
  for (i64 i = 0; i < M; ++i) {
    i64 A_i, B_i, C_i;
    std::cin >> A_i >> B_i >> C_i;
    bf.add_edge(A_i - 1, B_i - 1, -C_i);
  }
  const auto result = bf.calc(0);
  if (result.distances[N - 1] == std::numeric_limits<i64>::min()) {
    std::cout << "inf" << std::endl;
  } else {
    std::cout << -result.distances[N - 1] << std::endl;
  }
  return 0;
}

Measured memory_bytes: 384