#include <bits/stdc++.h>
using namespace std;
const int INF = 2123123123;
bool cf(pair<int, int> x, pair<int, int> y) {
  return x.second - x.first < y.second - y.first;
}
int main() {
  int N, M, mini = INF;
  scanf("%d %d", &N, &M);
  for (int i = 0; i < M; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    mini = min(mini, r - l + 1);
  }
  int jalan = 0;
  printf("%d\n", mini);
  for (int i = 0; i < N; i++) {
    printf("%d", jalan % mini);
    jalan++;
    if (i == N - 1)
      printf("\n");
    else
      printf(" ");
  }
  return 0;
}
