#include <bits/stdc++.h>
using namespace std;
const int MXN = 1e6 + 30;
const int MAXN = 1e5 + 123;
const long long INF = 1e9 + 7;
const long long BINF = 1e15;
const int MOD = 1e9 + 7;
const long double EPS = 1e-15;
long long n, m;
long long mn = INF;
long long ans[MXN];
pair<long long, pair<long long, long long> > a[MXN];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) ans[i] = -1;
  for (int i = 1; i <= m; i++) {
    cin >> a[i].second.first >> a[i].second.second;
    a[i].first = (a[i].second.second - a[i].second.first);
    mn = min(mn, a[i].first + 1);
  }
  cout << mn << '\n';
  for (int i = 1; i <= n; i++) {
    cout << i % mn << ' ';
  }
  return 0;
}
