#include <bits/stdc++.h>
using namespace std;
typedef vector<vector<int> > VVI;
typedef priority_queue<int, vector<int>, greater<int> > PQ;
int main() {
  int n, m, len = 1e9;
  cin >> n >> m;
  while (m--) {
    int l, r;
    cin >> l >> r;
    len = min(r - l + 1, len);
  }
  cout << len << endl;
  for (int i = 1, j = 0; i <= n; i++) {
    if (j == len) j = 0;
    cout << j << " ";
    j++;
  }
  return 0;
}
