#include <bits/stdc++.h>
using namespace std;
const int INF = 0x6fffffff;
const int MINF = 0x80000000;
const int mod = 1000000007;
const int cons = 1005;
const double pi = 3.141592653589793;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int ans = INF;
  for (int i = 0; i < m; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    ans = min(ans, r - l + 1);
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) {
    printf("%d ", i % ans);
  }
  return 0;
}
