#include <bits/stdc++.h>
using namespace std;
template <typename item>
item abs(item i) {
  if (i < 0) i = -i;
  return i;
}
long long int mod = 1000000000 + 7;
;
template <class typea>
typea POW(typea b, typea p) {
  typea res = 1;
  while (p) {
    if (p & 1) {
      res *= b;
      res %= mod;
    }
    b *= b;
    b %= mod;
    p /= 2;
  }
  return res;
}
int tc = 0;
long long int c;
long long int cnt[11][100 + 2][100 + 2];
void make() {
  for (long long int k = 0; k < c; k++)
    for (long long int i = 1; i <= 100; i++) {
      for (long long int j = 1; j <= 100; j++) {
        cnt[k][j][i] += cnt[k][j - 1][i];
      }
    }
  for (long long int k = 0; k < c; k++)
    for (long long int i = 1; i <= 100; i++) {
      for (long long int j = 1; j <= 100; j++) {
        cnt[k][i][j] += cnt[k][i][j - 1];
      }
    }
}
long long int result(long long int mx, long long int my, long long int x,
                     long long int y, long long int k) {
  return cnt[k][mx][my] - cnt[k][mx][y - 1] - cnt[k][x - 1][my] +
         cnt[k][x - 1][y - 1];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, m;
  cin >> n >> m;
  long long int mn = INT_MAX;
  long long int a, b;
  while (m--) {
    cin >> a >> b;
    mn = min(mn, b - a + 1);
  }
  cout << mn << "\n";
  for (int i = 0; i < n; i++) {
    cout << i % (mn) << " ";
  }
  return 0;
}
