#include <bits/stdc++.h>
using namespace std;
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy8[] = {1, -1, 0, 0, 1, -1, 1, -1};
const double GRS = (1 + sqrt(5)) / 2;
long long power(int X, int P) {
  long long ans = 1;
  for (int i = 1; i <= P; i++) {
    ans = ans * (long long)X;
  }
  return ans;
}
long long ABS(long long A, long long B) {
  long long ret = A - B;
  if (ret < 0) return -ret;
  return ret;
}
long long MOD = 1000000007;
const long long BIGMAX = power(2, 63) - 1;
long long ADD(long long X, long long Y) {
  if (X + Y < 0)
    return (X - MOD) + Y;
  else if (X + Y >= MOD)
    return X + Y - MOD;
  else
    return X + Y;
}
long long prod(long long X, long long Y) {
  if (Y == 0 || X <= (BIGMAX / Y)) return (X * Y) % MOD;
  long long result = 0;
  if (X > Y) swap(X, Y);
  while (X > 0) {
    if (X & 1 != 0) {
      result = ADD(result, Y);
    }
    X >>= 1;
    Y -= MOD - Y;
    if (Y < 0) Y = Y + MOD;
  }
  return result;
}
long long bigmod(long long a, long long b) {
  long long x = 1, y = a % MOD;
  while (b > 0) {
    if (b % 2 == 1) {
      x = prod(x, y);
    }
    y = prod(y, y);
    b /= (long long)2;
  }
  return x;
}
long long MODINVERSE(long long a) { return bigmod(a, MOD - 2); }
long long ncrdp[900][1000];
long long NCR(int n, int r) {
  if (r == 1)
    return n;
  else if (n == r)
    return 1;
  else {
    if (ncrdp[n][r] != -1)
      return ncrdp[n][r];
    else {
      ncrdp[n][r] = NCR(n - 1, r) + NCR(n - 1, r - 1);
      return ncrdp[n][r];
    }
  }
}
const int MAXN = 1400005;
int status[(MAXN / 32) + 10];
vector<int> primelist;
bool check(int n, int pos) { return (bool)(n & (1 << pos)); }
int SET(int n, int pos) { return n = n | (1 << pos); }
void sieve() {
  int sqrtN = int(sqrt(MAXN));
  status[1 >> 5] = SET(status[1 >> 5], 1 & 31);
  for (int j = 4; j <= MAXN; j = j + 2)
    status[j >> 5] = SET(status[j >> 5], j & 31);
  for (int i = 3; i <= sqrtN; i = i + 2) {
    if (check(status[i >> 5], i & 31) == 0) {
      for (int j = i * i; j <= MAXN; j = j + (i << 1)) {
        status[j >> 5] = SET(status[j >> 5], j & 31);
      }
    }
  }
  primelist.push_back(2);
  for (int i = 3; i <= MAXN; i = i + 2) {
    if (check(status[i >> 5], i & 31) == 0) {
      primelist.push_back(i);
    }
  }
}
long long arr[123456];
int main() {
  int n, m;
  long long mn = 99999999999999;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    long long x, y;
    scanf("%I64d %I64d", &x, &y);
    mn = min(mn, y - x + 1);
  }
  printf("%I64d\n", mn);
  for (int i = 0; i < n; i++) {
    printf("%I64d ", i % mn);
  }
}
