1 #include <bits/stdc++.h>
2 using namespace std;
3 struct edge
4 {
5 int v, nxt;
6 }e[2000005];
7 int fst[10005], label[10005], s[10005], vis[10005];
8 priority_queue<pair<int, int> > PQ;
9
10 void addedge(int i, int u, int v)
11 {
12 e[i] = (edge){v, fst[u]}, fst[u] = i;
13 }
14
15 int main()
16 {
17 int n, m, u, v, ans = 0;
18 scanf("%d%d", &n, &m);
19 for(int i = 1; i <= m; ++i)
20 {
21 scanf("%d%d", &u, &v);
22 addedge(i << 1, u, v);
23 addedge(i << 1 | 1, v, u);
24 }
25 for(int i = 1; i <= n; ++i)
26 PQ.push(make_pair(0, i));
27 for(int i = n; i; --i)
28 {
29 u = PQ.top().second, PQ.pop();
30 while(vis[u])
31 u = PQ.top().second, PQ.pop();
32 s[i] = u, vis[u] = -1;
33 for(int j = fst[u]; j; j = e[j].nxt)
34 {
35 v = e[j].v;
36 if(vis[v]) continue;
37 PQ.push(make_pair(++label[v], v));
38 }
39 }
40 memset(label, 0, sizeof(label));
41 for(int i = n; i; --i)
42 {
43 for(int j = fst[s[i]]; j; j = e[j].nxt)
44 vis[label[e[j].v]] = i;
45 for(int j = 1; ; ++j)
46 if(vis[j] != i)
47 {
48 label[s[i]] = j, ans = max(ans, j);
49 break;
50 }
51 }
52 printf("%d\n", ans);
53 return 0;
54 }