#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100007;
int n, m, l, r;
int main() {
  cin >> n >> m;
  int ans;
  for (int i = 1; i <= m; i++) {
    cin >> l >> r;
    ans = min(ans, r - l + 1);
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) {
    cout << i % ans << ' ';
  }
  return 0;
}
