#include <bits/stdc++.h>
using namespace std;
int n, m, rst;
int s[100003];
char f[100003];
vector<pair<int, int> > l;
bool cp(pair<int, int> a, pair<int, int> b) {
  return a.second - a.first < b.second - b.first;
}
int main(void) {
  int a, b;
  for (; ~scanf("%d%d", &n, &m);) {
    memset(s, -1, sizeof(s));
    for (; m--;) {
      scanf("%d%d", &a, &b);
      l.push_back(make_pair(a, b));
    }
    sort(l.begin(), l.end(), cp);
    m = 1 + l[0].second - l[0].first;
    int z = 0;
    for (int i = 1; i <= n; i++) {
      s[i] = z++;
      if (z == m) z = 0;
    }
    printf("%d\n", m);
    for (int i = 1; i <= n; i++) {
      printf("%s%d", i > 1 ? " " : "", s[i]);
    }
    puts("");
  }
  return 0;
}
