#include <bits/stdc++.h>
using namespace std;
int inf = 2147483647;
const long long ll = 9223372036854775807, ninf = 1000000000;
const double eps = 1e-6;
const long long nll = 223372036854775807;
int A[100005] = {};
int main() {
  int a, b;
  while (cin >> a >> b) {
    int ans = inf;
    pair<int, int> id;
    for (int i = 0; i < b; i++) {
      int x, y;
      cin >> x >> y;
      if (y - x + 1 < ans) {
        ans = min(ans, y - x + 1);
      }
    }
    cout << ans << '\n';
    int cnt = 0;
    for (int i = 1; i <= a; i++) {
      cout << cnt << " ";
      cnt++;
      cnt %= ans;
    }
    cout << '\n';
  }
  return 0;
}
