#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int length = INF;
  for (int i = 0; i < (m); ++i) {
    int a, b;
    cin >> a >> b;
    int cand = b - a + 1;
    length = min(cand, length);
  }
  cout << length << '\n';
  length--;
  int tmp = length;
  for (int i = (1); i < (n + 1); ++i) {
    cout << tmp << " ";
    tmp--;
    if (tmp == -1) tmp = length;
  }
  return 0;
}
