#include <bits/stdc++.h>
using namespace std;
int n, m;
int sum[123456];
vector<pair<int, int> > v;
int main() {
  cin >> n >> m;
  int mn = 1e9;
  for (int i = 0, l, r; i < m; i++) {
    scanf("%d%d", &l, &r);
    mn = min(mn, r - l + 1);
  }
  cout << mn << endl;
  int ct = 0;
  for (int i = 0; i < n; i++) {
    printf("%d ", ct);
    ct++;
    if (ct == mn) ct = 0;
  }
}
