#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, ans = 1e9;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    ans = min(ans, r - l + 1);
  }
  printf("%d\n", ans);
  int x = 0;
  for (int i = 1; i <= n; i++) {
    printf("%d ", x);
    x = (x + 1) % ans;
  }
  puts("");
  return 0;
}
