#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int res = 1000000001;
  for (int i = 0; i < m; i++) {
    int l, r;
    scanf("%i %i", &l, &r);
    res = (r - l < res ? r - l : res);
  }
  res++;
  cout << res << endl;
  for (int i = 0; i < n; i++) printf("%i ", i % res);
  return 0;
}
