#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e4 + 22;
int n, m;
void solve() {
  int l, r;
  cin >> n >> m;
  int val = INT_MAX;
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    val = min(val, r - l + 1);
  }
  cout << val << "\n";
  for (int i = 0; i < n; i++) cout << i % val << " ";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
