#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxn = 1e5 + 7;
const long long maxe = 1e6 + 7;
const long long INF = 1e9 + 7;
const double PI = acos(-1);
int dx[4] = {0, 0, 1, -1};
int dy[4] = {-1, 1, 0, 0};
inline void Max(int &a, int b) {
  if (b > a) a = b;
}
inline void Min(int &a, int b) {
  if (a == -1 || b < a) a = b;
}
int n, m, l[maxn];
;
int a[maxn];
pair<int, int> p[maxn];
int main() {
  cin >> n >> m;
  memset(a, 0, sizeof(a));
  int id = 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &p[i].first, &p[i].second);
    l[i] = p[i].second - p[i].first;
    if (l[i] < l[id]) id = i;
  }
  int t = 0;
  int ans = l[id] + 1;
  for (int i = 1; i <= n; i++) {
    a[i] = t++;
    t %= ans;
  }
  cout << ans << endl;
  for (int i = 1; i <= n; i++) cout << a[i] << " ";
  cout << endl;
  return 0;
}
