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