#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int res = n;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    res = min(res, b - a + 1);
  }
  cout << res << "\n";
  for (int i = 0, num = 0; i < n; i++, num = (num + 1) % res) {
    cout << num << " ";
  }
  cout << "\n";
}
