#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ;
  int n, m, l[N], r[N], a[N], min = N, ind = -1;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i];
    if ((r[i] - l[i] + 1) < min) {
      min = r[i] - l[i] + 1;
      ind = i;
    }
  }
  cout << min << endl;
  for (int i = l[ind] - 1; i < r[ind]; i++) a[i] = i - l[ind] + 1;
  for (int i = l[ind] - 2; i >= 0; i--) {
    if (a[i + 1] == 0)
      a[i] = min - 1;
    else
      a[i] = a[i + 1] - 1;
  }
  for (int i = r[ind]; i < n; i++) {
    if (a[i - 1] == min - 1)
      a[i] = 0;
    else
      a[i] = a[i - 1] + 1;
  }
  for (int i = 0; i < n; i++) cout << a[i] << " ";
  return 0;
}
