#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
struct Line {
  long long l, r;
} lines[maxn];
long long ans[maxn];
bool cmp(Line A, Line B) { return (A.r - A.l - 1) < (B.r - B.l - 1); }
int main(void) {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    long long l, r;
    cin >> l >> r;
    lines[i].l = l;
    lines[i].r = r;
  }
  sort(lines + 1, lines + 1 + m, cmp);
  long long ans = lines[1].r - lines[1].l + 1;
  cout << ans << "\n";
  for (long long i = 0; i < n; i++) {
    cout << (i % ans) << " ";
  }
  cout << "\n";
  return 0;
}
