#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
int n, k, p[MAXN], sol;
pair<int, int> a[MAXN];
vector<pair<int, int> > v;
int main() {
  scanf("%d %d", &n, &k);
  for (int i = (0); i < int(k); i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    a[i] = make_pair(x, y);
    v.push_back(make_pair(y - x + 1, i));
  }
  sort((v).begin(), (v).end());
  int j = 0;
  for (int i = (a[v[0].second].first - 1); i < int(a[v[0].second].second);
       i++) {
    p[i] = j;
    j++;
  }
  for (int i = a[v[0].second].first - 2; i >= 0; i--)
    p[i] = (p[i + 1] - 1 + v[0].first) % v[0].first;
  for (int i = a[v[0].second].second; i < n; i++)
    p[i] = (p[i - 1] + 1) % v[0].first;
  printf("%d\n", v[0].first);
  for (int i = (0); i < int(n); i++) printf("%d ", p[i]);
  puts("");
  return 0;
}
