#include <bits/stdc++.h>
using namespace std;
int all[100008];
int main() {
  int minn = 1000000007;
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    minn = min(minn, r - l);
  }
  printf("%d\n", minn + 1);
  minn++;
  int counter = 0;
  for (int i = 0; i < n; i++) printf("%d ", i % minn);
}
