#include <bits/stdc++.h>
int main() {
  int n, m, i, min, l, r;
  scanf("%d %d", &n, &m);
  min = n;
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &l, &r);
    if (r - l + 1 < min) min = r - l + 1;
  }
  printf("%d\n", min);
  printf("%d", 1 % min);
  for (i = 2; i <= n; i++) printf(" %d", i % min);
}
