#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  int minn = N;
  while (M--) {
    int left, right;
    scanf("%d%d", &left, &right);
    minn = min(minn, right - left + 1);
  }
  printf("%d\n", minn);
  for (int i = 1; i <= N; i++) printf("%d ", i % minn);
  printf("\n");
  return 0;
}
