#include #include #include #include #include #include #include #include #include #include using namespace std; struct UnionFind { vector par; vector siz; UnionFind(long long N) : par(N), siz(N) { for(long long i = 0; i < N; i++){ par[i] = i; siz[i] = 1; } } long long root(long long x) { if (par[x] == x) return x; return par[x] = root(par[x]); } long long unite(long long x, long long y) { long long rx = root(x); long long ry = root(y); if (rx == ry) return rx; if (siz[rx] > siz[ry]) swap(rx, ry); par[rx] = ry; siz[ry] += siz[rx]; return ry; } bool same(long long x, long long y) { long long rx = root(x); long long ry = root(y); return rx == ry; } long long size(long long x){ return siz[root(x)]; } }; int main(){ int N, M, mx=0, pu, pv; cin >> N >> M; vector u(M), v(M); for (int i=0; i> u[i] >> v[i]; UnionFind tree(N+1); vector ans(N+1); for (int i=M-1; i>=0; i--){ pu = tree.root(u[i]); pv = tree.root(v[i]); if (pu == pv) ans[pu]++; else{ tree.unite(pu, pv); ans[tree.root(pu)] = max(ans[pu], ans[pv])+1; } } for (int i=1; i<=N; i++) mx = max(mx, ans[i]); cout << mx << endl; return 0; }