#include <bits/stdc++.h>
using namespace std;
int a[100000];
int main() {
  int n, m;
  cin >> n >> m;
  int l, r, numpos;
  int ans = 1000000;
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    if (ans > r + 1 - l) {
      ans = r + 1 - l;
      numpos = l - 1;
    }
  }
  cout << ans << '\n';
  for (int i = 0; numpos + i < n; i++) {
    a[numpos + i] = i % ans;
  }
  r = ans - 1;
  for (int i = numpos - 1; i >= 0; i--) {
    a[i] = r;
    r = (r - 1 + ans) % ans;
  }
  for (int i = 0; i < n; i++) cout << a[i] << " ";
  return 0;
}
