use io::*;
use std::*;

fn solve(N: i64, M: i64, x: Vec<i64>, y: Vec<i64>) {
    let mut map: collections::HashMap<usize, Vec<usize>> = collections::HashMap::new();
    for (xval, yval) in x.iter().zip(y.iter()) {
        if map.get(&(*xval as usize)).is_some() {
            map.get_mut(&(*xval as usize)).unwrap().push(*yval as usize);
        }
        else {
            map.insert(*xval as usize, vec![*yval as usize]);
        }
    }
    // println!("{:?}", map);
    let mut dp = vec![0; N as usize + 1];
    fn topo(curr: usize, map: &collections::HashMap<usize, Vec<usize>>, dp: &mut Vec<usize>) -> usize {
        if dp[curr] != 0 {
            return dp[curr];
        } else {
            if map.get(&curr).is_some() {
                for &n in map.get(&curr).unwrap().iter() {
                    dp[curr] = cmp::max(dp[curr], topo(n, map, dp) + 1);
                }
                return dp[curr];
            } else {
                return 0;
            }
        }
    }
    for i in (1..dp.len()) {
        if dp[i] == 0 {
            topo(i, &map, &mut dp);
        }
    }
    let mut res = (0usize, 0usize);
    for (idx, value) in dp.iter().enumerate() {
        if *value > res.1 {
            res.1 = *value;
            res.0 = idx;
        }
    }
    println!("{}", res.1);
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fn main() {
    let con = read_string();
    let mut scanner = Scanner::new(&con);
    let mut N: i64;
    N = scanner.next();
    let mut M: i64;
    M = scanner.next();
    let mut x: Vec<i64> = vec![0i64; (M) as usize];
    let mut y: Vec<i64> = vec![0i64; (M) as usize];
    for i in 0..(M) as usize {
        x[i] = scanner.next();
        y[i] = scanner.next();
    }
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(move || solve(N, M, x, y)).unwrap().join().unwrap();
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

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

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 23624