#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, ans, a, b;
  scanf("%d%d", &n, &m);
  ans = n;
  while (m--) {
    scanf("%d%d", &a, &b);
    ans = min(ans, b - a + 1);
  }
  printf("%d\n", ans);
  for (i = n; i >= 1; i--) printf("%d ", i % ans);
  printf("\n");
  return 0;
}
