#include <bits/stdc++.h>
using namespace std;
int n, m;
int l, r;
int main() {
  scanf("%d%d", &n, &m);
  int anws = INT_MAX;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &l, &r);
    anws = min(anws, r - l + 1);
  }
  printf("%d\n", anws);
  for (int i = 1; i <= n; i++) printf("%d ", i % anws);
}
