#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
class Solution {
 public:
  void solve(std::istream& in, std::ostream& out) {
    int n, m;
    in >> n >> m;
    int len = inf;
    for (int i = 0; i < m; i++) {
      int l, r;
      in >> l >> r;
      len = min(len, r - l + 1);
    }
    int k = 0;
    out << len << endl;
    for (int i = 0; i < n; i++) {
      out << k++ << ' ';
      k %= len;
    }
  }
};
void solve(std::istream& in, std::ostream& out) {
  out << std::setprecision(15);
  int T = 1;
  if (0) in >> T;
  Solution solution;
  if (true)
    while (T--) solution.solve(in, out);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  istream& in = cin;
  ostream& out = cout;
  solve(in, out);
  return 0;
}
