#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  int n, m;
  cin >> n >> m;
  int minL = INF;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    chkmin(minL, b - a + 1);
  }
  cout << minL << '\n';
  for (int i = 0; i < n; i++) {
    cout << i % minL << " ";
  }
  return 0;
}
