#include <bits/stdc++.h>
using namespace std;
int res, n, k, ans = INT_MAX;
int a[100500];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    int x, y;
    cin >> x >> y;
    ans = min(ans, y - x + 1);
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) cout << (i) % ans << " ";
  return 0;
}
