#include <bits/stdc++.h>
using namespace std;
struct dt {
  int x, y, z;
};
struct df {
  int x, y, z, t;
};
struct strint {
  string s;
  int x;
};
struct vt {
  int x, y;
};
bool operator<(const vt &a, const vt &b) {
  if (a.x == b.x) {
    return a.y < b.y;
  } else {
    return a.x < b.x;
  }
}
int qan(int x) {
  int g = 1;
  while ((x / 10) > 0) {
    g++;
    x = x / 10;
  }
  return g;
}
int qanl(long long x) {
  int g = 1;
  while ((x / 10) > 0) {
    g++;
    x = x / 10;
  }
  return g;
}
int srj(int x) {
  int g = 0;
  while (x > 0) {
    g = g * 10 + x % 10;
    x = x / 10;
  }
  return g;
}
int srjl(long long x) {
  long long g = 0;
  while (x > 0) {
    g = g * 10 + x % 10;
    x = x / 10;
  }
  return g;
}
vt a[100007];
int b[2007], m, c[2007][2007];
bool d[2007];
int e[2007], A[2007][2007];
vector<int> g[100007];
bool f[100007], cl[2007][2007];
string r[2007];
map<string, int> mypa;
bool colour[100007];
long long dist[100007];
const long long NMAX = 9999999999;
map<int, int> my;
void dfs(int z) {
  for (int i = 0; i < g[z].size(); i++) {
    if (!f[g[z][i]]) {
      f[g[z][i]] = true;
      dfs(g[z][i]);
    }
  }
}
int main() {
  long long i, j, k, l, h, t, r, n, ans = 0;
  string s, s1, s2, s3;
  int maxim = LONG_MAX / 2;
  char sa[100007], sar[2007];
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> a[i].x >> a[i].y;
    if (a[i].y - a[i].x < maxim) {
      maxim = a[i].y - a[i].x + 1;
      t = i + 1;
    }
  }
  cout << maxim << endl;
  for (i = 0; i < n; i++) {
    cout << i % maxim << " ";
  }
  cout << endl;
  ;
  return 0;
}
