#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, mn, a, b, x, i;
  cin >> n >> k;
  mn = 1LL << 60;
  while (k--) {
    cin >> a >> b;
    mn = min(mn, b - a + 1);
  }
  cout << mn << endl;
  cout << 0;
  x = 0;
  for (i = 2; i <= n; i++) {
    x = (x + 1) % mn;
    cout << ' ' << x;
  }
  cout << endl;
}
