#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
} f[100005];
bool cmp(struct node a, struct node b) { return a.y - a.x < b.y - b.x; }
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> f[i].x >> f[i].y;
  sort(f, f + m, cmp);
  int mx = f[0].y - f[0].x + 1;
  printf("%d\n", mx);
  for (int i = 0; i < n; i++) printf(i == 0 ? "%d" : " %d", (i + 1) % mx);
  return 0;
}
