#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
pair<int, int> p[100010];
int l[100010], r[100010];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d %d", &l[i], &r[i]);
  for (int i = 1; i <= m; i++) p[i] = pair<int, int>(l[i], r[i]);
  int ans = 0x3f3f3f3f;
  for (int i = 1; i <= m; i++) ans = min(ans, r[i] - l[i] + 1);
  printf("%d\n", ans);
  int first = 0, second = 0;
  for (int i = 1; i <= m; i++) {
    if (r[i] - l[i] + 1 == ans) {
      first = l[i];
      second = r[i];
      break;
    }
  }
  for (int i = 1; i <= n; i++) {
    int rr = i % (second - first + 1);
    printf("%d ", rr);
  }
  return 0;
}
