#include <bits/stdc++.h>
using namespace std;
const int INF = 987654321;
int n, m, lo, hi, ans = INF, A[100010];
vector<pair<int, int>> vp;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &lo, &hi);
    ans = min(ans, hi - lo + 1);
    vp.emplace_back(lo, hi);
  }
  sort(vp.begin(), vp.end(),
       [&](const pair<int, int>& l, const pair<int, int>& r) {
         return l.second == r.second ? l.first < r.first : l.second < r.second;
       });
  memset(A, -1, sizeof(A));
  for (const auto& pii : vp) {
    lo = pii.first;
    hi = pii.second;
    int idx = lo, last = 0;
    for (int i = hi; i >= lo; --i) {
      if (A[i] != -1) {
        last = (A[i] + 1) % ans;
        idx = i + 1;
        break;
      }
    }
    for (int i = idx; i <= hi; ++i) {
      A[i] = last;
      ++last;
      last %= ans;
    }
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; ++i) {
    printf("%d ", A[i] == -1 ? n : A[i]);
  }
}
