#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m, mex = N, ans[N];
pair<int, int> a[N];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int l, r;
    cin >> l >> r;
    a[i] = {l, r};
    mex = min(mex, r - l + 1);
  }
  int cur = 0;
  cout << mex << '\n';
  for (int i = 1; i <= n; ++i) {
    if (cur == mex) cur = 0;
    cout << cur++ << ' ';
  }
}
