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