#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  int minn = 0x3f3f3f3f, x, y;
  pair<int, int> v[100050];
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &x, &y);
    v[i] = make_pair(x - 1, y - x + 1);
    minn = min(y - x + 1, minn);
  }
  sort(v, v + m);
  cout << minn << endl;
  int num = 0;
  int idx = 0;
  int tam = 0;
  for (int i = 0; i < n; i++) {
    if (idx < m) {
      if (i >= v[idx].first && tam <= 0) {
        tam = minn;
        idx++;
        num = 0;
      }
    }
    printf("%d ", num);
    num++;
    tam--;
  }
  puts("");
  return 0;
}
