#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
long long mas[N];
long long l[N];
long long r[N];
int main() {
  long long tests = 1;
  while (tests--) {
    long long n, m;
    cin >> n >> m;
    long long ans = (long long)(1e9 + 7);
    for (long long i = 0; i < m; i++) {
      cin >> l[i] >> r[i];
      ans = min(ans, r[i] - l[i] + 1);
    }
    cout << ans << "\n";
    long long cur = 0;
    for (long long i = 0; i < n; i++) {
      cur %= ans;
      cout << cur << " ";
      cur++;
    }
  }
  return 0;
}
