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