#include #include using namespace std; using namespace atcoder; int main() { int N, M, ans = 0; cin >> N >> M; dsu uf(N); vector u(M), v(M), dp(N); for( int i = 0; i < M; i++ ) { cin >> u[i] >> v[i]; u[i]--; v[i]--; } reverse(u.begin(), u.end()); reverse(v.begin(), v.end()); for( int i = 0; i < M; i++ ) { int ul = uf.leader(u[i]), vl = uf.leader(v[i]), m = max(dp[ul], dp[vl]); dp[ul] = m+1; dp[vl] = m+1; uf.merge(u[i], v[i]); } for( int i = 0; i < N; i++ ) { ans = max(ans, dp[i]); } cout << ans << endl; }