#include using namespace std; class dsu { vector p; vector sz; public: dsu(int n) : p(n), sz(n, 1) { iota(p.begin(), p.end(), 0); } inline int get(int x) { if (x == p[x]) { return x; } return p[x] = get(p[x]); } inline bool unite(int x, int y) { x = get(x); y = get(y); if (x != y) { if (sz[x] < sz[y]) { swap(x, y); } p[y] = x; sz[x] += sz[y]; return true; } return false; } inline int size(int x) { x = get(x); return sz[x]; } }; int main() { iostream::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; vector> A(m); for (auto &p : A) { int x, y; cin >> x >> y; x--, y--; p = {x, y}; } vector cnt(n); reverse(A.begin(), A.end()); dsu uf(n + 1); for (auto [x, y] : A) { int px = uf.get(x), py = uf.get(y); uf.unite(x, y); if (px == py) { cnt[uf.get(x)] = cnt[px] + 1; } else { cnt[uf.get(x)] = max(cnt[px], cnt[py]) + 1; } } cout << *max_element(cnt.begin(), cnt.end()) << '\n'; return 0; }