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