#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, k = 100000, a, b;
  scanf("%d %d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    if (b - a + 1 < k) {
      k = b - a + 1;
    }
  }
  j = 0;
  i = 1;
  printf("%d\n", k);
  while (i <= n) {
    printf("%d ", j);
    j = (j + 1) % k;
    i++;
  }
  printf("\n");
  return 0;
}
