#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
const long long INF = 2e18;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m, i;
  cin >> n >> m;
  long long l, r, ml, mr, md = INF;
  for (i = 0; i < m; i++) {
    cin >> l >> r;
    if (r - l <= md) {
      md = r - l;
      ml = l;
      mr = r;
    }
  }
  long long tab[n + 1];
  long long j = 0;
  for (i = ml; i <= mr; i++) {
    tab[i] = j;
    j++;
  }
  j = mr - ml;
  for (i = ml - 1; i >= 1; i--) {
    tab[i] = j;
    j--;
    if (j < 0) j = mr - ml;
  }
  j = 0;
  for (i = mr + 1; i <= n; i++) {
    tab[i] = j;
    j++;
    if (j > mr - ml) j = 0;
  }
  cout << mr - ml + 1 << "\n";
  for (i = 1; i <= n; i++) {
    cout << tab[i] << " ";
  }
  return 0;
}
