//vanitas vanitatum et omnia
#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128; 
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}      
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii; 
typedef vector<int> vi;  
typedef vector<pii> vp; 
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=1e5+5;
int n,m,sz[N],f[N],id[N],c[N];

int find(int x) {return x==id[x]?x:id[x]=find(id[x]);}
void upd(int x,int y) {
  per(i,n,x) chmin(f[i],f[i-x]+y);
}

signed main() {
  n=read(), m=read();
  rep(i,1,n) id[i]=i;
  rep(i,1,m) {
    int u=read(), v=read();
    u=find(u),v=find(v);
    if(u!=v) id[u]=v;
  }
  rep(i,1,n) sz[find(i)]++;
  rep(i,1,n) if(sz[i]) c[sz[i]]++;
  rep(i,1,n) f[i]=N;
  rep(i,1,n) if(c[i]) {
    rep(h,0,20) 
      if((1<<h)<=c[i])
        upd(i<<h,1<<h), c[i]-=(1<<h);
    if(c[i]) upd(c[i]*i,c[i]);
  }
  rep(i,1,n) {
    if(f[i]==N) puts("-1");
    else printf("%d\n",f[i]-1);
  }
  return 0;
}