#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t = 1;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long len = n, l, r;
    for (long long i = 0; i < m; i++) {
      cin >> l >> r;
      len = min(len, r - l + 1);
    }
    cout << len << endl;
    for (long long i = 0; i < n; i++) {
      cout << (i % len) << " ";
    }
  }
  return 0;
}
