#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int min = INT32_MAX;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    if (r - l + 1 < min) min = r - l + 1;
  }
  cout << min << endl;
  int j = 0;
  for (int i = 0; i < n; i++) {
    if (j == min) j = 0;
    cout << j << " ";
    j++;
  }
  cout << endl;
  return 0;
}
