#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, mn = N, ans[N], l, r;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> l >> r;
    mn = min(mn, r - l + 1);
  }
  memset(ans, 0, sizeof ans);
  for (int i = 0; i < n; ++i) {
    ans[i] = i % mn;
  }
  cout << mn << endl;
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << " ";
  }
  return 0;
}
