#include <bits/stdc++.h>
using namespace std;
const int INFINITE = INT_MAX;
const int MAXNUM = 100005;
int n, len, res;
int arr[2][100005], ans[100005], te[100005];
void forxunhuan(int le, int ri) {
  for (int i = le; i <= ri; i++) ans[i] = i % res;
}
int main() {
  memset(arr, 0, sizeof(arr));
  memset(ans, 0, sizeof(ans));
  memset(te, 0, sizeof(te));
  int n, m, minte = 10000000, tex = 0, le, ri;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &arr[0][i], &arr[1][i]);
    tex = arr[1][i] - arr[0][i];
    if (minte > tex) {
      minte = tex;
      le = arr[0][i];
      ri = arr[1][i];
    }
  }
  res = ri - le + 1;
  forxunhuan(le, ri);
  forxunhuan(1, le - 1);
  forxunhuan(ri + 1, n);
  printf("%d\n%d", res, ans[1]);
  for (int i = 2; i <= n; i++) {
    printf(" %d", ans[i]);
  }
  printf("\n");
}
