#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, k, x, y;
  cin >> n >> m;
  k = n;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    if (x < y) swap(x, y);
    k = min(k, x - y + 1);
  }
  cout << k << "\n";
  for (int i = 1; i <= n; i += k) {
    for (int j = i; j < i + k && j <= n; j++) cout << j - i << " ";
  }
}
