#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  int ans = n;
  for (int i = 1; i <= m; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    ans = min(ans, r - l + 1);
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) {
    cout << i % ans << " ";
  }
  cout << endl;
}
