#include <bits/stdc++.h>
using namespace std;
template <typename P, typename Q>
ostream& operator<<(ostream& os, pair<P, Q> p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
int main(int argc, char* argv[]) {
  int n, m;
  while (scanf("%d%d", &n, &m) == 2) {
    const int N = 100000 + 5;
    int begin[N];
    int end[N];
    fill(begin, begin + N, -1);
    fill(end, end + N, -1);
    int mn = 1 << 29;
    for (int i = 0; i < m; ++i) {
      int a, b;
      scanf("%d%d", &a, &b);
      --a;
      --b;
      begin[a] = i;
      end[b] = i;
      mn = min(mn, b - a + 1);
    }
    set<int> vis;
    int x[N];
    int z = 0;
    for (int i = 0; i < N; ++i) {
      if (begin[i] != -1) {
        vis.insert(begin[i]);
      }
      if (vis.size()) {
        x[i] = z++;
        z %= mn;
      } else {
        z = 0;
      }
      if (end[i] != -1) {
        vis.erase(end[i]);
      }
    }
    printf("%d\n", mn);
    for (int i = 0; i < n; ++i) {
      if (i) printf(" ");
      printf("%d", x[i]);
    }
    puts("");
  }
  return 0;
}
