#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, m, solutie = 999999999, k, l;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> k >> l;
    solutie = min(solutie, l - k + 1);
  }
  cout << solutie << '\n';
  for (i = 1; i <= n; i++) cout << i % solutie << " ";
  return 0;
}
