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