#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int maxn = 100005;
const int INF = 1e9 + 7;
int n, m;
int main() {
  while (cin >> n >> m) {
    int tp = INF;
    for (int i = 1; i <= m; i++) {
      int x, y;
      cin >> x >> y;
      tp = min(tp, (y - x + 1));
    }
    cout << tp << endl;
    int p = n / tp;
    for (int i = 1; i <= p; i++) {
      for (int j = 0; j < tp; j++) cout << j << " ";
    }
    int q = n % tp;
    for (int j = 0; j < q; j++) cout << j << " ";
    cout << endl;
  }
  return 0;
}
