#include <bits/stdc++.h>
using namespace std;
int n, m;
int l[10001], r[10001];
void solve() {
  cin >> n >> m;
  int L;
  L = n;
  for (int i = 0; i < m; ++i) {
    int l, r;
    cin >> l >> r;
    L = min(r - l + 1, L);
  }
  cout << L << endl;
  for (int i = 0; i < n; ++i) cout << i % L << ' ';
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  solve();
  return 0;
}
