#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
long long base = 37;
long long large = 1000000000000000000LL;
int main() {
  int n, m;
  cin >> n >> m;
  int ans = 1000000000;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    ans = min(ans, y - x + 1);
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) {
    cout << i % ans << " ";
  }
  cout << endl;
  return 0;
}
