#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ans = 100123;
  for (int i = 1; i <= m; i++) {
    int l, r;
    cin >> l >> r;
    ans = min(ans, r - l);
  }
  cout << ans + 1 - 1 + 1 << endl;
  int ok = 0;
  for (int i = 1; i <= n; i++) {
    cout << ok << ' ';
    if (ok == ans)
      ok = 0;
    else
      ok++;
  }
  return 0;
}
