#include <bits/stdc++.h>
using namespace std;
inline int min(int a, int b) { return a < b ? a : b; }
int main() {
  int n, m, l, r, min_v = 100001;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    min_v = min(min_v, r - l + 1);
  }
  cout << min_v << endl;
  cout << "0";
  for (int i = 1; i < n; i++) cout << " " << i % min_v;
  cout << endl;
  return EXIT_SUCCESS;
}
