#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int p, q;
  int min_ = 1e9 + 7;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &p, &q);
    min_ = min(min_, q - p + 1);
  }
  printf("%d\n", min_);
  for (int i = 0, ctr = 0; i < n; ++i, ctr = (ctr + 1) % min_) {
    printf("%d ", ctr);
  }
}
