#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main() {
  int n, m;
  cin >> n >> m;
  int maxn = INF;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    maxn = min(maxn, r - l + 1);
  }
  cout << maxn << endl;
  for (int i = 0; i < n; i++) {
    printf(i == n - 1 ? "%d\n" : "%d ", i % maxn);
  }
}
