#include <bits/stdc++.h>
using namespace std;
const int MX = 1e6 + 5;
int n, m, x = MX;
set<int> S;
void Solve() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    x = min(x, b - a + 1);
  }
  printf("%d\n", x);
  for (int i = 0; i < n; ++i) {
    printf("%d ", i % x);
  }
  puts("");
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  { Solve(); }
}
