#include <bits/stdc++.h>
using namespace std;
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
void file() {}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
}
int main() {
  file();
  fast();
  int n, m;
  cin >> n >> m;
  int mn = INT_MAX;
  while (m--) {
    int a, b;
    cin >> a >> b;
    mn = min(mn, b - a + 1);
  }
  cout << mn << "\n";
  int x = 0;
  for (int i = 0; i < n; i++) cout << i % mn << ' ';
  cout << "\n";
  return 0;
}
