#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  ios_base::sync_with_stdio(0);
  int mn = 1e9;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    mn = min(mn, r - l + 1);
  }
  int cur = 0;
  cout << mn << "\n";
  for (int i = 0; i < n; i++) {
    if (mn == cur) {
      cur = 0;
    }
    cout << cur << " ";
    cur++;
  }
  return 0;
}
