#include <bits/stdc++.h>
template <typename T>
inline bool MIN(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool MAX(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
inline int plu(int a, int b) {
  return a + b >= 1000000007 ? a + b - 1000000007 : a + b;
}
inline int sub(int a, int b) { return a - b < 0 ? a - b + 1000000007 : a - b; }
inline int mul(int a, int b) { return (long long)a * b % 1000000007; }
inline int inc(int &a, int b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
}
inline int dec(int &a, int b) {
  a -= b;
  if (a < 0) a += 1000000007;
}
using namespace std;
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  int ans = n;
  for (int i = 1; i <= m; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    MIN(ans, r - l + 1);
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; ++i) printf("%d ", i % ans);
  return 0;
}
