#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int len = INT_MAX;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    int k = abs(x - y) + 1;
    if (k < len) len = k;
  }
  int arr[n];
  for (int i = 0; i < n; i++) {
    arr[i] = i % len;
  }
  cout << len << endl;
  for (int i = 0; i < n; i++) cout << arr[i] << " ";
  return 0;
}
