#include <bits/stdc++.h>
using namespace std;
template <typename TP>
inline bool rd(TP& r) {
  r = 0;
  char tmp = getchar();
  while (tmp < '0' || tmp > '9') {
    if (tmp == EOF) return 0;
    tmp = getchar();
  }
  while ('0' <= tmp && tmp <= '9') {
    r = (r << 3) + (r << 1) + tmp - '0';
    tmp = getchar();
  }
  return 1;
}
int n, m;
long long mx = 1288727771;
int ans[100100];
int main() {
  rd(n), rd(m);
  int l, r;
  for (int i = 1; i <= m; i++) {
    rd(l), rd(r);
    mx = min(r - l + 1LL, mx);
  }
  printf("%I64d\n", mx);
  for (int i = 1; i <= n; i++) {
    printf("%d ", i % mx);
  }
  return 0;
}
