#include <bits/stdc++.h>
using namespace std;
int main() {
  int arraysize, numberOfSubarrays, firstIndex, lastIndex, cntr = 0;
  cin >> arraysize >> numberOfSubarrays;
  int theFinalArray[arraysize], mexs[numberOfSubarrays];
  for (int i = 0; i < numberOfSubarrays; i++) {
    cin >> firstIndex >> lastIndex;
    mexs[i] = lastIndex - firstIndex;
  }
  sort(mexs, mexs + numberOfSubarrays);
  cout << mexs[0] + 1 << endl;
  for (int i = 0; i < arraysize; i++) {
    theFinalArray[i] = cntr;
    cntr++;
    if (cntr > mexs[0]) cntr = 0;
    cout << theFinalArray[i] << " ";
  }
}
