#include <bits/stdc++.h>
const int MAXINT = 2147483640;
const long long MAXLL = 9223372036854775800LL;
const long long MAXN = 1000000;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  srand(time(0));
  int n, m, rs = MAXINT, i, l, r;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> l >> r;
    rs = min(rs, r - l + 1);
  }
  cout << rs << "\n";
  for (i = 0; i < n; i++) cout << i % rs << " ";
  return 0;
}
