#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define el cout<<"\n"
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define fz(i,a,n,z) for(int i=a;i<n;i+=z)
#define rep(i,a,n,z) for(int i=a;i>n;i-=z)
#define faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file(name) freopen(name".inp","r",stdin);freopen(name".out","w",stdout);
const int N = 1e5 + 5;
pair<int, int> A[N];
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> A[i].first >> A[i].second;
}
sort(A + 1, A + n + 1);
int res = 2;
for (int i = 2; i <= n; ++i) {
if (A[i].first <= A[i - 1].second) {
if (A[i - 1].second - A[i].first >= 1) {
A[i].second = A[i - 1].second;
}
else if (A[i - 1].second - A[i].first < 0) {
res += 2;
}
else {
res++;
}
}
else {
res += 2;
}
cout << A[i].first << " " << A[i].second << endl;
}
cout << res;
}
int main() {
faster
solve();
}
/*-----------------------END-----------------------*/
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBmaSBmaXJzdAojZGVmaW5lIHNlIHNlY29uZAojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIGVsIGNvdXQ8PCJcbiIKI2RlZmluZSBzeih4KSAoaW50KSh4KS5zaXplKCkKI2RlZmluZSBhbGwoeCkgKHgpLmJlZ2luKCksKHgpLmVuZCgpCiNkZWZpbmUgZjAoaSxuKSBmb3IoaW50IGk9MDtpPG47aSsrKQojZGVmaW5lIGYxKGksbikgZm9yKGludCBpPTE7aTw9bjtpKyspCiNkZWZpbmUgZnooaSxhLG4seikgZm9yKGludCBpPWE7aTxuO2krPXopCiNkZWZpbmUgcmVwKGksYSxuLHopIGZvcihpbnQgaT1hO2k+bjtpLT16KQojZGVmaW5lIGZhc3RlciBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTtjaW4udGllKDApO2NvdXQudGllKDApOwojZGVmaW5lIGZpbGUobmFtZSkgZnJlb3BlbihuYW1lIi5pbnAiLCJyIixzdGRpbik7ZnJlb3BlbihuYW1lIi5vdXQiLCJ3IixzdGRvdXQpOwpjb25zdCBpbnQgTiA9IDFlNSArIDU7CnBhaXI8aW50LCBpbnQ+IEFbTl07CnZvaWQgc29sdmUoKSB7CiAgICBpbnQgbjsKICAgIGNpbiA+PiBuOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKSB7CiAgICAgICAgY2luID4+IEFbaV0uZmlyc3QgPj4gQVtpXS5zZWNvbmQ7CiAgICB9CiAgICBzb3J0KEEgKyAxLCBBICsgbiArIDEpOwogICAgaW50IHJlcyA9IDI7CiAgICBmb3IgKGludCBpID0gMjsgaSA8PSBuOyArK2kpIHsKICAgICAgICBpZiAoQVtpXS5maXJzdCA8PSBBW2kgLSAxXS5zZWNvbmQpIHsKICAgICAgICAgICAgaWYgKEFbaSAtIDFdLnNlY29uZCAtIEFbaV0uZmlyc3QgPj0gMSkgewogICAgICAgICAgICAgICAgQVtpXS5zZWNvbmQgPSBBW2kgLSAxXS5zZWNvbmQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSBpZiAoQVtpIC0gMV0uc2Vjb25kIC0gQVtpXS5maXJzdCA8IDApIHsKICAgICAgICAgICAgICAgIHJlcyArPSAyOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgICAgcmVzKys7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZWxzZSB7CiAgICAgICAgICAgIHJlcyArPSAyOwogICAgICAgIH0KICAgICAgICBjb3V0IDw8IEFbaV0uZmlyc3QgPDwgIiAiIDw8IEFbaV0uc2Vjb25kIDw8IGVuZGw7CiAgICB9CiAgICBjb3V0IDw8IHJlczsKfQppbnQgbWFpbigpIHsKICAgIGZhc3RlcgogICAgc29sdmUoKTsKfQovKi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tRU5ELS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0qLwo=