#include <bits/stdc++.h>
using namespace std;
template <class T>
T max(T a, T b, T c) {
  return max(a, max(b, c));
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long> > subsets(m);
  for (auto(i) = 0; i < m; i++) cin >> subsets[i].first >> subsets[i].second;
  long long mn = 1e18 + 5;
  for (auto(i) = 0; i < m; i++)
    mn = min(mn, subsets[i].second - subsets[i].first + 1);
  cout << mn << '\n';
  long long numTimes = n / mn;
  for (auto(i) = 0; i < numTimes; i++) {
    for (auto(j) = 0; j < mn; j++) cout << j << ' ';
  }
  long long left = n - mn * numTimes;
  for (auto(i) = 0; i < left; i++) cout << i << ' ';
  return 0;
}
