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