#include <bits/stdc++.h>
using namespace std;
int n, m, ans = 1e9;
int a[100005];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return x * f;
}
inline void print(int x) {
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
int main() {
  n = read(), m = read();
  for (int i = 1, l, r; i <= m; i++)
    l = read(), r = read(), ans = min(ans, r - l + 1);
  for (int i = 1; i <= ans; i++) a[i] = i - 1;
  for (int i = ans + 1; i <= n; i++) a[i] = a[i - ans];
  print(ans);
  puts("");
  for (int i = 1; i <= n; i++) print(a[i]), putchar(' ');
  puts("");
  return 0;
}
