#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int K = 1e6 + 7;
const int mod = 1e9 + 7;
int n, m, a = 1e9;
int main(void) {
  int x, y;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) cin >> x >> y, a = min(y - x + 1, a);
  printf("%d\n", a);
  for (int i = 1; i <= n;)
    for (int j = 0; j < a && i <= n; j++, i++) printf("%d ", j);
  return 0;
}
