#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, m;
int ans;
int main() {
  scanf("%d%d", &n, &m);
  ans = n;
  for (int i = 0, l, r; i < m; i++) {
    scanf("%d%d", &l, &r);
    ans = (ans < r - l + 1 ? ans : r - l + 1);
  }
  printf("%d\n", ans);
  for (int i = 0, now = 0; i < n; i++, now++) {
    if (now == ans) now = 0;
    printf("%d ", now);
  }
  return 0;
}
