#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, mex = 1e9, len[100005];
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    len[i] = r - l;
    mex = min(len[i] + 1, mex);
  }
  printf("%d\n", mex);
  for (int i = 0; i < n; i++) printf("%d ", i % mex);
  return 0;
}
