#include <bits/stdc++.h>
using namespace std;
FILE *in;
FILE *out;
const int MAX = 100002;
int n, m;
int a[MAX][2];
int ans[MAX];
int main(void) {
  in = stdin;
  out = stdout;
  fscanf(in, "%d %d", &n, &m);
  int smallest = MAX;
  for (int i = 0; i < m; i++) {
    fscanf(in, "%d %d", &a[i][0], &a[i][1]);
    smallest = min(smallest, a[i][1] - a[i][0] + 1);
  }
  fprintf(out, "%d\n", smallest);
  for (int i = 0; i < n; i++)
    fprintf(out, "%d%c", i % smallest, i + 1 == n ? '\n' : ' ');
  return 0;
}
