#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long MX = 1e9;
const long long INF = 1e9;
void print_a(vector<int> v) {
  if (v.size()) cout << v[0];
  for (int i = 1; i < v.size(); ++i) cout << ' ' << v[i];
  cout << '\n';
}
long long gcd(long long a, long long b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  int l, r, ln, mn = INT_MAX;
  for (int i = 0; i < m; ++i) {
    cin >> l >> r;
    ln = r - l + 1;
    mn = min(mn, ln);
  }
  int mx = mn;
  vector<int> ans;
  for (int i = 0; i < n; ++i) {
    for (int j = i; j < min(i + mx, n); ++j) ans.push_back(j - i);
    i += (mx - 1);
  }
  cout << mx << '\n';
  print_a(ans);
  return 0;
}
