import java.io.{BufferedReader, InputStream, InputStreamReader}
import java.util.{Comparator, StringTokenizer}

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}

object Main {
  val MOD = 1000000007
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N, M = sc.nextInt()
    type Edge = ((Int, Int), Int)
    val E = Array.ofDim[Edge](M)
    (0 until M) foreach { i =>
      val a, b = sc.nextInt() - 1
      val c = sc.nextInt()
      E(i) = ((a, b), c)
    }

    val INF = Long.MinValue + 1000000000
    val d = Array.fill[Long](N)(INF)
    d(0) = 0

    var updated = false
    (0 until N) foreach { _ =>
      updated = false
      (0 until M) foreach { i =>
        val ((a, b), c) = E(i)
        if (d(a) + c > d(b)) {
          updated = true
          d(b) = d(a) + c
        }
      }
    }

    val ans = if (updated) "inf" else d(N - 1).toString
    println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

}
