#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, an = 1e9, k = 0, x, y, mex;
  cin >> n >> m;
  int a[n];
  while (m--) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    if (r - l + 1 < an) {
      x = l;
      y = r;
      mex = (r - l) + 1;
      an = r - l + 1;
    }
  }
  for (int i = x; i <= y; i++) a[i] = k++;
  k = 0;
  for (int i = y + 1; i < n; i++) {
    a[i] = k;
    k++;
    if (k == mex) k = 0;
  }
  k = mex - 1;
  for (int i = x - 1; i > -1; i--) {
    a[i] = k;
    k--;
    if (k < 0) k = mex - 1;
  }
  cout << mex << endl;
  for (int i = 0; i < n; i++) cout << a[i] << " ";
  return 0;
}
