#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const int N = 1e6;
int A[N];
int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  int len = n + 1;
  for (int i = 0; i < m; i++) {
    int l, r;
    scanf("%d", &l);
    scanf("%d", &r);
    len = min(len, r - l + 1);
  }
  int y = 0;
  for (int i = 0; i < n; i++) {
    if (y >= len) y = 0;
    A[i] = y++;
  }
  cout << len << endl;
  for (int i = 0; i < n; i++) cout << A[i] << " ";
  cout << endl;
  return 0;
}
