#include <bits/stdc++.h>
using namespace std;
vector<int> a;
void solve(int n, int m, int end) {
  int val = 0;
  for (int i = 0; i < n; i++) {
    a.push_back(val);
    val++;
    if (val == end) val = 0;
  }
  printf("%d\n", end);
  copy(a.begin(), a.end(), ostream_iterator<int>(cout, " "));
}
void read() {
  int n, m;
  int mini = 1e9 + 1;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    mini = min(mini, r - l + 2);
  }
  solve(n, m, mini - 1);
}
int main() {
  read();
  return 0;
}
