#include <bits/stdc++.h>
using namespace std;
pair<int, int> arr[100005];
int ans[100005];
bool mycmp(const pair<int, int>& a, const pair<int, int>& b) {
  if (a.second - a.first != b.second - b.first)
    return a.second - a.first < b.second - b.first;
  return a.first < b.first;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int mex = 1000000000;
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &arr[i].first, &arr[i].second);
    --arr[i].first;
    --arr[i].second;
    mex = min(mex, arr[i].second - arr[i].first + 1);
  }
  printf("%d\n", mex);
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    printf("%d%c", cnt, i == n - 1 ? '\n' : ' ');
    cnt = (cnt + 1) % mex;
  }
  return 0;
}
