#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  vector<pair<int, int>> vc;
  int ans = INT_MAX;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    vc.push_back({a, b});
    ans = min(ans, b - a + 1);
  }
  cout << ans << "\n";
  int j = 0;
  for (int i = 0; i < n; i++) {
    cout << j << " ";
    j++;
    j = j % ans;
  }
  cout << "\n";
  return 0;
}
