#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int N, M;
int A[MAXN], B[MAXN];
int main() {
  scanf("%d %d", &N, &M);
  int mnlen = N;
  for (int i = 1; i <= M; i++) {
    scanf("%d %d", &A[i], &B[i]);
    mnlen = min(mnlen, B[i] - A[i] + 1);
  }
  printf("%d\n", mnlen);
  for (int i = 0; i < N; i++) {
    printf("%d ", i % mnlen);
  }
  puts("");
}
