#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[202020];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int mn = 1e9;
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &p[i].first, &p[i].second);
    mn = min(mn, p[i].second - p[i].first + 1);
  }
  printf("%d\n", mn);
  for (int i = 0; i < n; ++i) {
    printf("%d%c", i % mn, " \n"[i == n - 1]);
  }
  return 0;
}
