#include <bits/stdc++.h>
using namespace std;
void print_ans(bool f) {
  if (f) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
long long int modular_pow(long long int base, long long int exponent,
                          long long int modulus) {
  long long int result = 1;
  while (exponent > 0) {
    if (exponent % 2 == 1) result = (result * base) % modulus;
    exponent = exponent >> 1;
    base = (base * base) % modulus;
  }
  return result;
}
long long int ask(long long int l, long long int r) {
  long long int x;
  cout << "? " << l << " " << r << endl;
  cin >> x;
  return x;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m, l, r, mn = INT_MAX;
  cin >> n >> m;
  vector<long long int> a(n);
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    mn = min(mn, r - l + 1);
  }
  long long int temp = 0;
  for (int i = 0; i < n; i++) {
    a[i] = temp;
    temp++;
    if (temp == mn) temp = 0;
  }
  cout << mn << endl;
  for (auto i : a) cout << i << " ";
  cout << endl;
}
