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