#include <bits/stdc++.h>
using namespace std;
constexpr long long INF = 1999999999999999997;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  int mx = INT_MAX;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    mx = min(mx, (r - l + 1));
  }
  cout << mx << endl;
  for (int i = 0; i < n; i++) {
    cout << i % mx << ' ';
  }
}
