#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const long long LINF = LLONG_MAX;
int main() {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> a(n, 0);
  int ind = 0, length = n + 1;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    if (length > r - l + 1) {
      length = r - l + 1;
      ind = l - 1;
    }
  }
  for (int i = ind, j = 0; i < n; i++, j++) {
    a[i] = j % length;
  }
  for (int i = ind - 1, j = length - 1; i >= 0;
       i--, j = (j - 1 + length) % length)
    a[i] = j;
  cout << length << endl;
  for (auto k : a) cout << k << ' ';
  return 0;
}
