#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long mn = n;
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    mn = min(mn, b - a + 1);
  }
  cout << mn << "\n";
  for (long long i = 0; i < n; i++) {
    cout << i % mn << " ";
  }
}
