#include <bits/stdc++.h>
using namespace std;
long long arr[111111];
long long l[111111], d[111111];
int main() {
  long long n, m, mini = 11111111, ind;
  scanf("%lld%lld", &n, &m);
  for (long long i = 0; i < m; i++) {
    scanf("%lld%lld", l + i, d + i);
    if (d[i] - l[i] + 1 < mini) {
      mini = d[i] - l[i] + 1;
      ind = i;
    }
  }
  for (long long i = l[ind]; i <= d[ind]; i++) arr[i] = i - l[ind];
  for (long long i = l[ind] - 1; i >= 1; i--) arr[i] = arr[i + mini];
  for (long long i = d[ind] + 1; i <= n; i++) arr[i] = arr[i - mini];
  printf("%lld\n", mini);
  for (long long i = 1; i <= n; i++) printf("%lld ", arr[i]);
}
