/**
 n m
 a1 b1
 ...
 am bm
*/

#include <ctime>
#include <cstdio>
#include <vector>
using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)

const int N = 1e5;
const int E = 2e5 * 2 + 1;
int n, m, cc, u[N];
int e = 1, head[N], to[E], next[E];

void add( int a, int b ) { // a --> b
  next[e] = head[a], to[e] = b, head[a] = e++;
}
void dfs( int v ) { // O(V)
  u[v] = cc;
  for (int e = head[v]; e != 0; e = next[e])
    if (!u[to[e]])
      dfs(to[e]);
}
int main() {
  scanf("%d%d", &n, &m);
  forn(i, m) {
    int a, b;
    scanf("%d%d", &a, &b), a--, b--; // 0..n-1
    add(a, b);
    add(b, a);
  }
  forn(i, n)
    if (!u[i])
      cc++, dfs(i);
  printf("%d\n", cc);
  forn(i, n)
    printf("%d ", u[i]);
  fprintf(stderr, "time = %.2f\n", 1. * clock() / CLOCKS_PER_SEC);
}