#include <bits/stdc++.h>
using namespace std;
const double PI = 2 * acos(0);
const int INF = INT_MAX;
int nextInt() {
  int x;
  scanf("%d", &x);
  return x;
}
long long nextLL() {
  long long x;
  scanf("%i64d", &x);
  return x;
}
int main() {
  int n = nextInt(), m = nextInt();
  int ans = INF;
  for (int i = 0; i < m; i++) {
    int l = nextInt(), r = nextInt();
    ans = min(ans, r - l);
  }
  ans++;
  cout << ans << endl;
  cout << 0;
  for (int i = 1; i < n; i++) {
    cout << ' ' << i % ans;
  }
  cout << endl;
}
