#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, l, r, a;
  cin >> n >> m;
  a = n;
  for (int i = 1; i <= m; i++) {
    cin >> l >> r;
    a = min(a, r - l + 1);
  }
  cout << a << endl;
  for (int i = 1; i <= n; i++) {
    printf("%d ", i % a);
  }
}
