#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int best = n + 1;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    best = min(b - a, best);
  }
  best++;
  cout << best << endl;
  for (int i = 0; i < n; i++) cout << i % best << " ";
  cout << endl;
}
