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