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