#include <bits/stdc++.h>
using namespace std;
int n, m, i, l, r, mex;
int main() {
  cin >> n >> m;
  mex = n;
  for (i = 1; i <= m; ++i) {
    cin >> l >> r;
    mex = min(mex, r - l + 1);
  }
  cout << mex << '\n';
  for (i = 0; i < n; ++i) cout << i % mex << ' ';
}
