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