#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct outputer;
struct outputable {};
const long double pi = acos(-1.l);
template <typename T>
inline auto sqr(T x) -> decltype(x * x) {
  return x * x;
}
template <typename T1, typename T2>
inline bool umx(T1& a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool umn(T1& a, T2 b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int N = 100000;
const int M = 100000;
struct Input {
  int n, m;
  int l[M], r[M];
  bool read() {
    if (!(cin >> n >> m)) {
      return 0;
    }
    for (int i = int(0); i < int(m); ++i) {
      scanf("%d%d", &l[i], &r[i]);
      --l[i];
    }
    return 1;
  }
  void init(const Input& input) { *this = input; }
};
struct Data : Input {
  int ans;
  int a[N];
  void write() {
    cout << ans << endl;
    for (int i = int(0); i < int(n); ++i) {
      if (i) {
        printf(" ");
      }
      printf("%d", a[i]);
    }
    puts("");
  }
};
namespace Main {
struct Solution : Data {
  void solve() {
    ans = n;
    for (int i = int(0); i < int(m); ++i) {
      umn(ans, r[i] - l[i]);
    }
    for (int i = int(0); i < int(n); ++i) {
      a[i] = i % ans;
    }
  }
  void clear() { *this = Solution(); }
};
}  // namespace Main
Main::Solution sol;
int main() {
  cout.setf(ios::showpoint | ios::fixed);
  cout.precision(20);
  sol.read();
  sol.solve();
  sol.write();
  return 0;
}
