#include <bits/stdc++.h>
using namespace std;
long long int m, mx = 43534543441, i, j, n, cnt = 0, t, q, tmp, flag = 0, k,
                 pos, x, y, z, ind, ind2, l, r, ans = 0, a, b, oc, un;
string s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    mx = min(b - a, mx);
  }
  j = 0;
  cout << mx + 1;
  cout << "\n";
  for (i = 0; i < n; i++) {
    cout << j << " ";
    j++;
    if (j > mx) j = 0;
  }
  return 0;
}
