#include <bits/stdc++.h>
using namespace std;
long long binpow(long long a, long long b);
void prime_factorization(long long n, vector<long long> &prime_factors);
long long gcd(long long a, long long b);
void speedup() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int find_par(int r, int par[]) {
  if (par[r] == r) return r;
  return par[r] = find_par(par[r], par);
}
void union_set(int a, int b, int par[], int node[]) {
  int u = find_par(a, par);
  int v = find_par(b, par);
  if (u != v) {
    par[v] = u;
    node[u] = node[u] + node[v];
  }
}
int checkbit(int n, int i) {
  if ((n & (1 << i))) {
    return 1;
  } else
    return 0;
}
int main() {
  speedup();
  int t = 1;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<int> ans(n);
    int l, r;
    int minlen = (int)1e7;
    for (int i = 0; i < m; i++) {
      cin >> l >> r;
      if (r - l + 1 < minlen) {
        minlen = r - l + 1;
      }
    }
    int mex = 0;
    for (int i = 0; i < n; i++) {
      if (mex == minlen) {
        mex = 0;
      }
      ans[i] = mex;
      mex++;
    }
    cout << minlen << "\n";
    for (int i = 0; i < n; i++) {
      cout << ans[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res *= a;
    a = a * a;
    b = b >> 1;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (b == 0) return 0;
  return gcd(b, a % b);
}
void prime_factorization(long long n, vector<long long> &prime_factors) {
  while (n % 2 == 0) {
    prime_factors.push_back(2);
    n = n / 2;
  }
  for (long long i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      prime_factors.push_back(i);
      n = n / i;
    }
  }
  if (n > 2) {
    prime_factors.push_back(n);
  }
}
