#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using vpii = vector<pii>;
using vpdd = vector<pdd>;
int64_t fuse(int i1, int i2) { return (((int64_t)i1) << 32) + i2; }
pii split(int64_t l) { return {(int)(l >> 32), (int)(l & 0xFFFFFFFF)}; }
static int constexpr dbg = 0;
int main(int argc, char *argv[]) {
  if (!dbg) {
    std::ios::sync_with_stdio(false);
  }
  int n, m;
  cin >> n >> m;
  int mn = INT_MAX;
  for (int i = 0; i < m; ++i) {
    int l, r;
    cin >> l >> r;
    mn = min(mn, r - l + 1);
  }
  cout << mn << endl;
  for (int i = 0; i < n; ++i) {
    cout << (i % mn) << " ";
  }
  return 0;
}
