#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, u, v;
  scanf("%d%d", &n, &m);
  int len = 25000000;
  while (m--) {
    scanf("%d%d", &u, &v);
    len = min(len, v - u + 1);
  }
  printf("%d\n0", len);
  for (int i = 1; i < n; i++) {
    printf(" %d", i % len);
  }
  puts("");
}
