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