#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 9;
const int N = 1e6 + 9;
int n, m, x, y, a[N];
pair<int, pair<int, int>> p[N];
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> x >> y, p[i] = {y - x, {x, y}};
  sort(p, p + m);
  for (int k = 0, i = p[0].second.first - 1; i < p[0].second.second; i++, k++)
    a[i] = k;
  m = p[0].second.first - 2;
  x = p[0].first;
  while (m >= 0) a[m] = a[m + x + 1], m--;
  m = p[0].second.second;
  while (m < n) a[m] = a[m - x - 1], m++;
  cout << x + 1 << endl;
  for (int i = 0; i < n; i++) cout << a[i] << " ";
  return 0;
}
