#pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) #define FOR(n) for(int i = 0; i < (int)n; i++) #define repi(i,a,b) for(int i = (int)a; i < (int)b; i++) #define pb push_back #define all(x) x.begin(),x.end() //#define mp make_pair #define vi vector #define vvi vector #define vll vector #define vvll vector #define vs vector #define vvs vector #define vc vector #define vvc vector #define pii pair #define pllll pair #define vpii vector> #define vpllll vector> #define vpis vector> #define vplls vector> #define vpsi vector> #define vpsll vector> template void chmax(T &a, const T &b) {a = (a > b? a : b);} template void chmin(T &a, const T &b) {a = (a < b? a : b);} using ll = long long; using ld = long double; using ull = unsigned long long; const ll INF = numeric_limits::max() / 2; const ld pi = 3.1415926535897932384626433832795028; const ll mod = 998244353; int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1}; int dy[] = {0, -1, 0, 1, -1, 1, -1, 1}; #define int long long //普通UnionFind -- Disjoing Set Union struct UnionFind { vector r; UnionFind(int n) { r = vector(n, -1); } int root(int x) { if(r[x] < 0) return x; return r[x] = root(r[x]); } bool unite(pair p) { return unite(p.first, p.second); } bool unite(int x, int y) { x = root(x); y = root(y); if(x == y) return false; if(r[x] > r[y]) swap(x, y); r[x] += r[y]; r[y] = x; return true; } bool issame(pair p) { return issame(p.first, p.second); } bool issame(int x, int y) { return root(x) == root(y); } int size(int x) { return -r[root(x)]; } int number_of_set() { set st; FOR(r.size()) st.insert(root(i)); return st.size(); } }; struct StronglyConnectedComponents { int n; //reversed_graph //辺を逆向きに貼りなおしたグラフ。 vector> graph, reversed_graph; vector order, component; vector used; void dfs(int v) { used[v] = 1; for(auto e : graph[v]) { if(used[e]) continue; dfs(e); } order.push_back(v); } void dfs2(int v, int k) { component[v] = k; for(auto e : reversed_graph[v]) { if(component[e] == -1) dfs2(e, k); } } StronglyConnectedComponents(vector> &G_) { n = G_.size(); graph = G_; reversed_graph.resize(n); component.assign(n, -1); used.resize(n); for(int v = 0; v < n; v++) { for(auto e : graph[v]) reversed_graph[e].push_back(v); } for(int v = 0; v < n; v++) if(!used[v]) dfs(v); int k = 0; //topoogical sort in all the sub trees reverse(order.begin(), order.end()); //いままでの強連結成分に含まれていなかったらDFS for(auto e : order) if(component[e] == -1) dfs2(e, k), k++; } //return if vertex(u, v) in same strongly connected component bool issame(int u, int v) { return component[u] == component[v]; } vector> rebuild() { //コンポーネント数 const int N = *max_element(component.begin(), component.end()) + 1; vector> rebuilded_graph(N); set> connected; for(int v = 0; v < N; v++) { for(auto e : graph[v]) { //同じ強連結成分に含まれていなくてかつ //その二つの強連結成分がグラフ上でつながれていなかったら if(component[v] != component[e] && !connected.count(make_pair(v, e))) { connected.insert(make_pair(v, e)); rebuilded_graph[component[v]].push_back(component[e]); } } } return rebuilded_graph; } vector> pull_groups() { const int N = *max_element(component.begin(), component.end()) + 1; vector> groups; for(int i = 0; i < n; i++) { groups[component[i]].push_back(i); } return groups; } }; void solve() { int n, m; cin >> n >> m; vpii edges; FOR(m) { int u, v; cin >> u >> v; --u; --v; edges.emplace_back(u, v); } UnionFind UF(n); vector done(n, false); vector ans(n, 1); vector ids; reverse(all(edges)); for(auto e : edges) { int r1 = UF.root(e.first); int r2 = UF.root(e.second); if(done[r1] || done[r2] || done[e.first] || done[e.second]) { int nans = max({ans[r1], ans[r2], ans[e.first], ans[e.second]}); ans[r1] = nans+1; ans[r2] = nans+1; ans[e.first] = nans+1; ans[e.second] = nans+1; for(auto e : ids) { done[e] = false; } ids.clear(); } done[r1] = true; done[r2] = true; done[e.first] = true; done[e.second] = true; ids.push_back(r1); ids.push_back(r2); ids.push_back(e.first); ids.push_back(e.second); UF.unite(e); } cout << *max_element(all(ans)) << endl; } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }