#include <bits/stdc++.h>
using namespace std;
struct obj {
  long long s, e;
};
int main() {
  long long n, m, ans = 1e10;
  cin >> n >> m;
  obj a[m];
  for (long long i = 0; i < m; ++i) {
    cin >> a[i].s >> a[i].e;
    ans = min(ans, a[i].e - a[i].s + 1);
  }
  cout << ans << "\n";
  for (long long i = 0; i < n; ++i) {
    cout << i % ans << " ";
  }
  cout << "\n";
  return 0;
}
