#include <bits/stdc++.h>
using namespace std;
long long arr[100010], dp[100010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, m, i, l, r, x, t;
  cin >> n >> m;
  x = 1000000000ll;
  for (i = 1; i <= m; i++) {
    cin >> l >> r;
    x = min(x, r - l + 1);
  }
  t = 0;
  for (i = 1; i <= n; i++) {
    arr[i] = t;
    t = (t + 1) % x;
  }
  cout << x << '\n';
  for (i = 1; i <= n; i++) {
    cout << arr[i] << " ";
  }
  return 0;
}
