#include using namespace std; #define rep(i,n) for(ll i=0;i=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define pqueue(x) priority_queue,greater> #define all(x) (x).begin(),(x).end() #define CST(x) cout<> #define rev(x) reverse(x); using ll=long long; using vl=vector; using vvl=vector>; using pl=pair; using vpl=vector; using vvpl=vector; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ll dy[9]={0,1,-1,0,1,1,-1,-1,0}; const ll dx[9]={1,0,0,-1,1,-1,1,-1,0}; template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } struct UnionFind { vector par; vector edge; UnionFind(int n) : par(n, -1),edge(n, 0) {} int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool same(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) { edge[x]++; return false; } if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; edge[x] += edge[y]+1; return true; } int size(int x) { return -par[root(x)]; } }; template< typename T > vector< T > slide_min(const vector< T > &v, int k) { deque< int > deq; vector< T > ret; for(int i = 0; i < v.size(); i++) { while(!deq.empty() && v[deq.back()] >= v[i]) { deq.pop_back(); } deq.push_back(i); if(i - k + 1 >= 0) { ret.emplace_back(v[deq.front()]); if(deq.front() == i - k + 1) deq.pop_front(); } } return ret; } int main(){ ll n,m;cin >> n >> m; UnionFind uf(n); rep(i,m){ ll a,b;cin >> a >> b; a--;b--;uf.merge(a,b); } vl v; rep(i,n){ if(uf.root(i)!=i)continue; v.push_back(uf.size(i)); } sort(all(v)); map mp; for(auto p:v){ if(p<=100)mp[p]++; } vl dp(n+1,INF);dp[0]=0; for(auto [val,k]:mp){ //cout << val <<" " << k << endl; vvl ndp(val); rep(i,n+1){ ndp[i%val].emplace_back(dp[i]-i/val); } rep(i,val){ deque deq; rep(j,ndp[i].size()){ while(!deq.empty()&&ndp[i][deq.back()]>=ndp[i][j]){ deq.pop_back(); } deq.push_back(j); dp[j*val+i]=ndp[i][deq.front()]+j; if(deq.front()<=j-k)deq.pop_front(); } } //rep(i,n+1)cout << dp[i] <<" ";cout << endl; } rep(i,v.size()){ if(v[i]<=100)continue; per(j,n+1){ if(j+v[i]