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