#include #include #include using namespace std; template struct union_find { int n; std::vector par; std::vector sz; std::vector dat; int num_of_components; union_find(int n) : n(n) { par.resize(n); sz.resize(n); dat.resize(n); for (int i = 0; i < n; i++) { par[i] = i; sz[i] = 1; } num_of_components = n; } union_find(std::vector &dat) : dat(dat) { union_find(dat.size()); } int find(int i) { assert(0 <= i && i < n); return (i == par[i]) ? i : par[i] = find(par[i]); } bool same(int i, int j) { assert(0 <= i && i < n); assert(0 <= j && j < n); return find(i) == find(j); } void unite(int i, int j) { assert(0 <= i && i < n); assert(0 <= j && j < n); i = find(i), j = find(j); if (sz[i] < sz[j]) { std::swap(i, j); } dat[i] = op(dat[i], dat[j]); if (i == j) { return; } par[j] = i; sz[i] += sz[j]; num_of_components--; } int size() { return n; } int size(int i) { assert(0 <= i && i < n); return sz[find(i)]; } T weight(int i) { assert(0 <= i && i < n); return dat[find(i)]; } int count() { return num_of_components; } bool is_root(int i) { assert(0 <= i && i < n); return i == find(i); } int operator[](int i) { return find(i); } }; int op(int a, int b) { return max(a, b) + 1; } int main() { int n, m; cin >> n >> m; union_find uf(n); int u[200005], v[200005]; for (int i = 0; i < m; i++) { cin >> u[i] >> v[i]; u[i]--; v[i]--; } for (int i = m - 1; i >= 0; i--) { uf.unite(u[i], v[i]); } int ans = 0; for (int x = 0; x < n; x++) { ans = max(ans, uf.weight(x)); } cout << ans << endl; }