#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  int mn = 1000000;
  for (auto i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    mn = min(mn, v - u + 1);
  }
  cout << mn << endl;
  int k = 0;
  for (auto i = 1; i <= n; i++) {
    cout << k << " ";
    k = (k + 1) % mn;
  }
  return 0;
}
