#include <bits/stdc++.h>
using namespace std;
clock_t time_p = clock();
void Time() {
  time_p = clock() - time_p;
  cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
const int INF = 1e9 + 7;
long double pi = 3.1415926535897932;
const long long INF64 = 9e18;
const long long mod = 1e9 + 7;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a;
  int x = m + 1, l, r;
  for (int i = 0; i < m; ++i) {
    int l, r;
    cin >> l >> r;
    x = min(x, r - l + 1);
  }
  for (int i = 0; i < x; ++i) a.push_back(i);
  cout << x << endl;
  for (int i = 0; i < n; ++i) {
    cout << a[i % (int)a.size()] << " ";
  }
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(35);
  int t;
  solve();
  Time();
  return 0;
}
