#include <bits/stdc++.h>
using namespace std;
pair<int, int> b[100005];
int a[100005] = {0};
int main() {
  std::ios_base::sync_with_stdio(0);
  int cases, caseno = 0, n, i, j, k, cnt, m, sum;
  cin >> n >> m;
  int mn = n;
  for (i = 0; i <= m - 1; i++) {
    cin >> b[i].first >> b[i].second;
    mn = min(mn, b[i].second - b[i].first + 1);
  }
  sort(b, b + m);
  j = 1;
  k = 0;
  for (i = 0; i <= m - 1; i++) {
    if (j < b[i].first) k = 0;
    j = max(j, b[i].first);
    while (j <= b[i].second) {
      a[j] = k;
      k++;
      j++;
      if (k == mn) {
        k = 0;
        break;
      }
    }
  }
  cout << mn << '\n';
  for (i = 1; i <= n; i++) cout << a[i] << " ";
  return 0;
}
