use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;

/*
負閉路には三種類ある
- sからtへの間にあるもの
- sから負閉路に到達してtには到達しないもの
- sから行けないもの
*/

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<usize>();
    let m = scan.read::<usize>();
    let mut edges = vec![];
    for _ in 0..m {
        let a = scan.read::<usize>()-1;
        let b = scan.read::<usize>()-1;
        let c = scan.read::<i64>();
        edges.push((a, b, -c));
    }
    let (d, neg) = bellman_ford(n, &edges, 0);
    if neg[n-1] { println!("inf");}
    else { println!("{}", -d[n-1]); }
}

#[allow(dead_code)]
fn bellman_ford(n: usize, edges: &Vec<(usize, usize, i64)>, s: usize) -> (Vec<i64>, Vec<bool>) {
    let mut d = vec![1i64<<60;n];
    d[s] = 0;
    for _ in 0..n-1 {
        for &(from, to, cost) in edges {
            if d[from] != 1i64<<60 && d[to] > d[from] + cost {
                d[to] = d[from] + cost;
            }
        }
    }
    let mut neg = vec![false;n];
    for _ in 0..n {
        for &(from, to, cost) in edges {
            if d[from] == 1i64<<60 {continue;}
            if d[to] > d[from] + cost {
                d[to] = d[from] + cost;
                neg[to] = true;
            }
            if neg[from] {
                neg[to] = true;
            }
        }
    }
    (d, neg)
}

#[allow(dead_code)]
fn find_negative_loop(n: usize, edges: &Vec<(usize, usize, i64)>) -> bool {
    let mut d = vec![0; n];
    for i in 0..n {for &(from, to, cost) in edges {
        if d[to] > d[from] + cost {
            d[to] = d[from] + cost;
            if i == n-1 {return true;}
        }
    }}
    return false;
}


// region template
#[allow(dead_code)]
fn iu(i: isize) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> isize { i as isize }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

#[allow(dead_code)]
fn alt<S, T>(v: Vec<S>) -> T where T: FromIterator<S> {
    v.into_iter().collect::<T>()
}

#[allow(dead_code)]
fn dup<S, T>(v: &[S]) -> T where T: FromIterator<S>, S: Clone {
    v.iter().cloned().collect::<T>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352