#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, x, y;
  scanf("%d", &n);
  scanf("%d", &m);
  int mn = n;
  for (i = 1; i <= m; ++i) {
    scanf("%d", &x);
    scanf("%d", &y);
    mn = min(mn, y - x + 1);
  }
  cout << mn << endl;
  for (i = 0, j = 0; i < n; ++i, ++j) {
    if (j == mn) j = 0;
    cout << j << " ";
  }
  return 0;
}
