#include <bits/stdc++.h>
int main() {
  int n, m, mex, i, l, r, nr;
  scanf("%d%d", &n, &m);
  mex = 1000000;
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &l, &r);
    if (r - l < mex) mex = r - l;
  }
  mex++;
  printf("%d\n", mex);
  nr = 0;
  for (i = 1; i <= n; i++) {
    printf("%d ", nr);
    nr = (nr + 1) % mex;
  }
  return 0;
}
