{$APPTYPE CONSOLE}
{$Q+,R+,O-,I+}

uses SysUtils;

Const
  MaxN=300;
  Fname='weakconn';

var n,a,b,m,i,j,k:integer;
    g:array [1..MaxN,1..MaxN] of boolean;
    t:array [1..MaxN,1..MaxN] of integer;

begin
  reset(input,Fname+'.in');
  rewrite(output,Fname+'.out');
repeat  
  read(n,m);
  fillchar(g,sizeof(g),0);
  fillchar(t,sizeof(t),63);
  for i:=1 to m do begin
    read(a,b);
    g[a,b]:=true;
    g[b,a]:=true;
    t[a,b]:=0;
    if t[b,a]<>0 then
      t[b,a]:=1;
  end;
  for k:=1 to n do
    for i:=1 to n do
      for j:=1 to n do
        if (g[i,k]) and (g[k,j]) and (t[i,k]+t[k,j]<t[i,j]) then begin
          g[i,j]:=true;
          t[i,j]:=t[i,k]+t[k,j];
        end;
  m:=0;
  for i:=1 to n do
    for j:=1 to n do
      if m<t[i,j] then
        m:=t[i,j];
  writeln(m);
until seekEof;
end.