#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int an = 1e9;
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    an = min(an, b - a + 1);
  }
  printf("%d\n", an);
  int x = 0;
  for (int i = 0; i < n; ++i) {
    printf("%d ", x);
    ++x;
    if (x == an) x = 0;
  }
}
