#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
int l[N], r[N];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> l[i] >> r[i];
  int best = 1e9;
  for (int i = 0; i < m; i++) best = min(best, r[i] - l[i] + 1);
  vector<int> res(n);
  cout << best << endl;
  for (int i = 0; i < n; i++) cout << (i % best) << " ";
  cout << endl;
}
