#include <bits/stdc++.h>
using namespace std;
long long int __gcd(long long int a, long long int b) {
  return (a % b) ? __gcd(b, a % b) : b;
}
bool prime(long long int k) {
  for (long long int i = 2; i * i <= k; i++)
    if (k % i == 0) {
      return false;
    }
  return true;
}
void pdash(int n = 1) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 30; j++) {
      cout << "-";
    }
    cout << "\n";
  }
}
void solve() {
  int n, m;
  cin >> n >> m;
  int len = numeric_limits<int>::max();
  int l[m], r[m];
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i];
    len = min(r[i] - l[i], len);
  }
  len++;
  cout << len << "\n";
  for (int i = 0; i < n; i++) {
    cout << i % len << " ";
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
}
