#include <bits/stdc++.h>
const int maxn = 1e5 + 10;
using namespace std;
int gcd(int p, int q) { return q == 0 ? p : gcd(q, p % q); }
long long qpow(long long p, long long q) {
  long long f = 1;
  while (q) {
    if (q & 1) f = f * p;
    p = p * p;
    q >>= 1;
  }
  return f;
}
inline long long read() {
  long long x = 0;
  int 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;
}
int n, m, k, t, ans;
int main() {
  int i, j;
  ans = 1e9;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) scanf("%d%d", &j, &k), ans = min(ans, k - j + 1);
  printf("%d\n", ans);
  for (i = 1; i <= n; i++) {
    printf("%d ", (i - 1) % ans);
  }
  return 0;
}
