#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void write(long long a) {
  if (a < 0) {
    printf("-");
    a = -a;
  }
  if (a >= 10) write(a / 10);
  putchar(a % 10 + '0');
}
inline void writeln(long long a) {
  write(a);
  printf("\n");
}
int n, m, ans = 2147483647, t;
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    ans = min(ans, y - x + 1);
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) {
    printf("%d ", t);
    t++;
    if (t >= ans) t = 0;
  }
}
