#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const int MAX_N = 200000; vector _parent; vector _rank; vector _size; class UnionFind { public: UnionFind(int n) { for (int i = 0; i < n; ++i) { _parent.push_back(i); _rank.push_back(0); _size.push_back(1); } } int find(int x) { if (_parent[x] == x) { return x; } else { return _parent[x] = find(_parent[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (_rank[x] < _rank[y]) { _parent[x] = y; _size[y] += _size[x]; } else { _parent[y] = x; _size[x] += _size[y]; if (_rank[x] == _rank[y]) ++_rank[x]; } } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return _size[find(x)]; } }; int main() { int N, M; cin >> N >> M; UnionFind uf(N + 1); vector counter(N + 1, 0); int U[M]; int V[M]; for (int i = 0; i < M; ++i) { cin >> U[i] >> V[i]; } for (int i = M - 1; i >= 0; --i) { int u = U[i]; int v = V[i]; int p1 = uf.find(u); int p2 = uf.find(v); if (uf.same(u, v)) { counter[p1]++; } else { uf.unite(u, v); int p = uf.find(u); counter[p] = max(counter[p1], counter[p2]) + 1; } } cout << counter[uf.find(1)] << endl; return 0; }