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