#include <bits/stdc++.h>
using namespace std;
const int ALPH = 26;
int main() {
  iostream::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int ans = n;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    ans = min(ans, b - a + 1);
  }
  cout << ans << endl;
  for (int i = 0; i < n; ++i) cout << i % ans << " ";
  cout << endl;
  return 0;
}
