#include <bits/stdc++.h>
using namespace std;
int N, M, A, B, i, z = INT_MAX;
int main() {
  for (cin >> N >> M; i < M; i++) {
    cin >> A >> B;
    z = min(z, B - A + 1);
  }
  cout << z;
  while (N) {
    cout << '\n' << N-- % z;
  }
}
