#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m, i, mini = 999999999999;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    long long dif = b - a;
    mini = min(mini, dif);
  }
  vector<long long> a(n, 0);
  long long p = 0;
  for (i = 0; i < n; i++) {
    a[i] = p;
    p++;
    if (p == (mini + 1)) p = 0;
  }
  cout << (mini + 1) << endl;
  for (i = 0; i < n; i++) cout << a[i] << " ";
  return 0;
}
