#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  while (T--) {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> v;
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      v.push_back(make_pair(x, y));
    }
    sort(v.begin(), v.end(), [](pair<int, int> &p1, pair<int, int> &p2) {
      int x = p1.second - p1.first + 1;
      int y = p2.second - p2.first + 1;
      if (x < y) return true;
      if (x > y) return false;
      return (p1.first < p2.first);
    });
    int res = v[0].second - v[0].first + 1;
    cout << res << endl;
    int a[n + 1], j = 0;
    memset(a, -1, sizeof a);
    int c = 0;
    for (int i = 1; i <= n; i++) {
      cout << c % res << " ";
      c++;
    }
    cout << endl;
  }
  return 0;
}
