#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int res[n + 1];
  for (int i = 1; i <= n; ++i) res[i] = -1;
  vector<pair<int, int>> vec(m);
  int mn = 1e5;
  for (auto& it : vec)
    cin >> it.first >> it.second, mn = min(mn, it.second - it.first);
  sort(vec.begin(), vec.end());
  int a = 1;
  for (auto it : vec) {
    a = max(a, it.first);
    if (res[a] == -1) res[a] = 0;
    while (a <= n and a <= it.first + mn and res[a] != -1) ++a;
    if (a == n + 1) break;
    for (int i = a; i <= it.first + mn; ++i) {
      res[i] = (res[i - 1] + 1) % (mn + 1);
    }
    a = it.first + mn;
  }
  cout << mn + 1 << endl;
  for (int i = 1; i <= n; ++i) {
    if (res[i] == -1) res[i] = 0;
    cout << res[i] << " ";
  }
  cout << endl;
}
