#include <bits/stdc++.h>
using namespace std;
int main() {
  const int N = 1e5 + 5;
  int n, m, mn = 1e9, cnt = 0;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    mn = min(mn, r - l + 1);
  }
  cout << mn << endl;
  for (int i = 0; i < n; i++) cout << cnt++ << ' ', cnt %= mn;
}
