#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> mas(m);
  int ans = INT_MAX / 2;
  for (int i = 0; i < m; i++) {
    cin >> mas[i].first >> mas[i].second;
    ans = min(ans, mas[i].second - mas[i].first + 1);
  }
  cout << ans << endl;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cout << cnt << " ";
    cnt++;
    if (cnt == ans) cnt = 0;
  }
  return 0;
}
