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