'use strict';
(function(input){
  input=input.trim().split(/\n/).map(str=>str.split(/\s+/).map(x=>x-0));
  const N=input[0][0];
  const M=input[0][1];
  input.shift();
  const Node=function(){
    var t=this;
    t.children=[];
    t.scanned=false;
    t.height=0;
  }
  
  Node.prototype.measureHeight=function(){
    var t=this;
    while(t.children.length>0){
      let child=t.children.pop();
      t.height=Math.max(t.height,child.measureHeight());
    }
    //console.log('.');
    t.scanned=true;
    return t.height+1;
  }
  
  const nodes=new Array(N+1).fill(0).map(x=>new Node);
  //console.log(nodes);
  input.forEach(function(xy){
    var p=xy[0],c=xy[1];
    nodes[p].children.push(nodes[c]);
  });
  //console.log(nodes);
  var ans=0;
  for(let i=1;i<=N;i++){
    if(nodes[i].scanned)
      continue;
    ans=Math.max(ans,nodes[i].measureHeight());
  }
  //console.log(nodes);
  ans--;
  console.log(ans);
})(require('fs').readFileSync('/dev/stdin','utf8'));