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