#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]

#[allow(unused_macros)]
macro_rules! invec {
    ( $ t : ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s
                .trim()
                .split_whitespace()
                .map(|s| s.parse::<$t>().unwrap())
                .collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }};
}

#[allow(unused_macros)]
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

use std::cmp;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;

pub struct BellmanFord {
    edges: Vec<(usize, usize, i64)>,
    dist: Vec<i64>,
    isLoop: bool,
    goalLoop: bool,
    n: usize,
    s: usize,
    start: usize,
}

impl BellmanFord {
    //0-indexedに直しておくこと！
    pub fn new(n: usize, e: &Vec<(usize, usize, i64)>) -> Self {
        BellmanFord {
            edges: e.clone(),
            dist: vec![INF_I64; n],
            n: n,
            s: e.len(),
            isLoop: false,
            goalLoop: false,
            start: 0,
        }
    }
    //0-indexedに直しておくこと！
    pub fn calc(&mut self, start: usize) {
        self.start = start;
        self.dist[start] = 0;
        for i in 0..self.n {
            for j in 0..self.s {
                let (f, t, c) = self.edges[j];
                if self.dist[t] > self.dist[f] + c {
                    self.dist[t] = self.dist[f] + c;
                    if i == self.n - 1 {
                        self.isLoop = true;
                    }
                    if i == self.n - 1 && t == self.n - 1 {
                        self.goalLoop = true;
                    }
                }
            }
        }
    }
    pub fn dist(&mut self, to: usize) -> i64 {
        return self.dist[to];
    }
}

fn main() {
    input! {
       n: usize,
       m:usize,
       edges :  [(usize,usize,i64);m],
    }

    let mut ans = 0;

    let mut edges = edges;
    edges = edges
        .iter()
        .map(|&(x, y, z)| (x - 1, y - 1, z * -1))
        .collect();
    let mut bf = BellmanFord::new(n, &edges);
    bf.calc(0);

    if bf.goalLoop {
        println!("{}", "inf");
    } else {
        ans = bf.dist(n - 1);
        println!("{}", ans * -1);
    }
}


Measured memory_bytes: 4352