#include <bits/stdc++.h>
using namespace std;
long long int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
void solve() {
  int n, m;
  cin >> n >> m;
  int mex = INT_MAX, curr = 0;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    mex = min(mex, r - l + 1);
  }
  cout << mex << '\n';
  for (int i = 0; i < n; i++) {
    cout << curr << " ";
    curr++;
    if (curr == mex) curr = 0;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(NULL);
  cin.tie(NULL);
  ;
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
