#include <bits/stdc++.h>
using namespace std;
using li = long int;
using lli = long long int;
bool comp(pair<int, int> a, pair<int, int> b) {
  return (a.second - a.first) < (b.second - b.first);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > pairs(m);
  for (auto &x : pairs) cin >> x.first >> x.second;
  sort(pairs.begin(), pairs.end(), comp);
  int mini = pairs[0].second - pairs[0].first + 1;
  vector<int> ans(n);
  for (int i = 0; i < n; ++i) {
    ans[i] = i % mini;
  }
  cout << mini << "\n";
  for (auto &y : ans) cout << y << " ";
  cout << "\n";
  ;
}
