#include<bits/stdc++.h>
using namespace std;

int rt[200000];
int ans[200000];
int getroot(int n){
  if(rt[n]==-1)return n;
  return rt[n]=getroot(rt[n]);
}

void unite(int a,int b){
  a=getroot(a),b=getroot(b);
  if(a!=b){
    rt[a]=b;
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  fill(rt,rt+200000,-1);
  fill(ans,ans+200000,0);
  int N,M;
  cin>>N>>M;
  vector<array<int,2>>E(M);
  for(auto &i:E)cin>>i[0]>>i[1],--i[0],--i[1];
  int ret=0;
  for(int i=M-1;i>=0;i--){
    int p=max(ans[getroot(E[i][0])],ans[getroot(E[i][1])]);
    unite(E[i][0],E[i][1]);
    ans[getroot(E[i][0])]=p+1;
    ret=max(ret,ans[getroot(E[i][0])]);
  }
  cout<<ret<<'\n';
}