#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
struct node {
  node *l, *r;
  int v;
  node() : l(nullptr), r(nullptr), v(0) {}
  node(int v) : l(nullptr), r(nullptr), v(v) {}
  node(node *t) : l(t->l), r(t->r), v(t->v) {}
};
typedef node *tree;
tree build(int l, int r) {
  tree nt = new node();
  if (r - l == 1) {
    return nt;
  }
  int m = (l + r) >> 1;
  nt->l = build(l, m);
  nt->r = build(m, r);
  nt->v = (nt->l ? nt->l->v : 0) + (nt->r ? nt->r->v : 0);
  return nt;
}
tree modify(tree t, int l, int r, int p, int nv) {
  tree nt = new node(t);
  if (r - l == 1) {
    nt->v += nv;
    return nt;
  }
  int m = (l + r) >> 1;
  if (p < m)
    nt->l = modify(t->l, l, m, p, nv);
  else
    nt->r = modify(t->r, m, r, p, nv);
  nt->v = (nt->l ? nt->l->v : 0) + (nt->r ? nt->r->v : 0);
  return nt;
}
int query(tree t, int l, int r, int L, int R) {
  if (l == L && r == R) return t->v;
  int m = (l + r) >> 1;
  int sum = 0;
  if (L < m) sum += query(t->l, l, m, L, min(m, R));
  if (R > m) sum += query(t->r, m, r, max(m, L), R);
  return sum;
}
tree t[N];
map<int, int> lp;
void print(tree t) {
  if (t->l) print(t->l);
  if (!t->l && !t->r) cout << t->v << ' ';
  if (t->r) print(t->r);
}
vector<pair<int, long long>> g[N];
long long d[N], a[N];
map<long long, int> coord;
vector<int> ord;
int u[N], tin[N], tout[N], ans[N], ti = 0;
void dfs(int v) {
  if (u[v]) return;
  u[v] = 1;
  tin[v] = ++ti;
  ord.push_back(v);
  for (auto i : g[v]) {
    if (!u[i.first]) {
      d[i.first] = d[v] + i.second;
      dfs(i.first);
    }
  }
  tout[v] = ti;
}
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 2; i <= n; ++i) {
    int p, w;
    cin >> p >> w;
    g[i].push_back({p, w});
    g[p].push_back({i, w});
  }
  dfs(1);
  t[0] = build(0, N);
  int ptr = 0;
  for (int i = 1; i <= n; ++i) {
    if (!coord.count(a[i])) coord[a[i]] = ptr++;
    if (!coord.count(d[i])) coord[d[i]] = ptr++;
  }
  for (int i = 1; i <= n; ++i) {
    t[i] = modify(t[i - 1], 0, N, coord[d[ord[i - 1]]], 1);
  }
  for (int i = 0; i < n; ++i) {
    ans[ord[i]] = query(t[tout[ord[i]]], 0, N, 0, coord[a[ord[i]]]) -
                      query(t[tin[ord[i]] - 1], 0, N, 0, coord[a[ord[i]]])
                  << '\n';
  }
  for (int i = 1; i <= n; ++i) {
    cout << ans[i] << ' ';
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  int mex = 1e9;
  for (int i = 0; i < m; ++i) {
    int l, r;
    cin >> l >> r;
    mex = min(mex, r - l + 1);
  }
  cout << mex << '\n';
  for (int i = 0; i < n; ++i) {
    cout << (i % mex) << ' ';
  }
}
