#include <bits/stdc++.h>
using namespace std;
int n, k, min1 = 1000000;
pair<int, int> angka[100005];
int main() {
  cin >> n >> k;
  for (int x = 1; x <= k; x++) {
    int a, b;
    cin >> a >> b;
    int tmp = b - a + 1;
    min1 = min(min1, tmp);
  }
  cout << min1 << endl;
  int cnt = 1, hitung = 0;
  while (cnt <= n) {
    if (hitung == min1) {
      hitung = 0;
    }
    if (cnt == n) {
      cout << hitung << endl;
      break;
    }
    cout << hitung << " ";
    cnt++;
    hitung++;
  }
  return 0;
}
