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