#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
void seriy() {
  cin.tie(0);
  cout.tie(0);
}
signed main() {
  seriy();
  long long n, m;
  cin >> n >> m;
  long long mn = 2e9 + 8;
  for (long long i = 0; i < m; i++) {
    long long l, r;
    cin >> l >> r;
    mn = min(mn, r - l + 1);
  }
  cout << mn << endl;
  vector<long long> ans(n);
  for (long long i = 0; i < n; i++) {
    ans[i] = i % mn;
  }
  for (auto i : ans) cout << i << " ";
  return 0;
}
