#include <bits/stdc++.h>
using namespace std;
const int MXN = 1e6 + 10;
int ans[MXN];
int main() {
  int N, M;
  cin >> N >> M;
  int mex = N;
  while (M--) {
    int L, R;
    cin >> L >> R;
    mex = min(mex, R - L + 1);
  }
  cout << mex << "\n";
  for (int i = 0; i < N; ++i) {
    cout << i % mex << " ";
  }
  return 0;
}
