#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 2e6 + 5;
const int K = (1 << 17) + 10;
const long long int INF = 2e18 + 500;
const int inf = 0x7fffffff;
const int SQRT = 500;
const int lgN = 20;
int main(int argc, char const *argv[]) {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  int ans = inf;
  while (q--) {
    int l, r;
    cin >> l >> r;
    ans = min(ans, r - l + 1);
  }
  cout << ans << '\n';
  for (int i = 0; i < n; i++) cout << i % ans << ' ';
  cout << '\n';
  return 0;
}
