#include <bits/stdc++.h>
using namespace std;
void my_dbg() { cout << endl; }
template <typename Arg, typename... Args>
void my_dbg(Arg A, Args... B) {
  cout << ' ' << A;
  my_dbg(B...);
}
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9 + 7;
const int maxN = 3e5 + 2;
void solve() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  int mn = inf;
  for (int i = 0; i < (int)m; i++) {
    int l, r;
    scanf("%d", &l);
    scanf("%d", &r);
    mn = min(mn, r - l + 1);
  }
  printf("%d\n", (int)(mn));
  for (int i = 0; i < (int)n; i++) printf("%d ", (int)(i % mn));
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
