#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio (false);
int n, m;
cin>>n>>m;
int min_diff = 100005;
for (int i=0; i<n; i++) {
int l, r;
cin>>l>>r;
min_diff = min (min_diff, r - l + 1);
}
cout<<min_diff<<endl;
for (int i=0; i<n; i++) {
cout<< (i%min_diff)<<" ";
}
cout<<endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCWlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8gKGZhbHNlKTsKCWludCBuLCBtOwoJY2luPj5uPj5tOwoJaW50IG1pbl9kaWZmID0gMTAwMDA1OwoJZm9yIChpbnQgaT0wOyBpPG47IGkrKykgewoJCWludCBsLCByOwoJCWNpbj4+bD4+cjsKCQltaW5fZGlmZiA9IG1pbiAobWluX2RpZmYsIHIgLSBsICsgMSk7Cgl9Cgljb3V0PDxtaW5fZGlmZjw8ZW5kbDsKCWZvciAoaW50IGk9MDsgaTxuOyBpKyspIHsKCQljb3V0PDwgKGklbWluX2RpZmYpPDwiICI7Cgl9Cgljb3V0PDxlbmRsOwoJcmV0dXJuIDA7Cn0=