#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
using pii = pair<int, int>;
using l = long;
using ll = long long;
using ull = unsigned long long;
void solve();
int main() {
  high_resolution_clock::time_point t1 = high_resolution_clock::now();
  { solve(); }
  high_resolution_clock::time_point t2 = high_resolution_clock::now();
  const auto duration = duration_cast<milliseconds>(t2 - t1).count();
  cout.flush();
  cerr << "--------------" << endl;
  cerr << "Elapsed Time: " << duration << "ms" << endl;
  cerr << "--------------" << endl;
  ;
}
set<pii> I;
vector<pii> ans;
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    pii p;
    cin >> p.first;
    cin >> p.second;
    if (p.first > p.second) swap(p.first, p.second);
    I.insert(p);
  }
  auto it = I.begin();
  pii seg = *it;
  while (++it != end(I)) {
    auto seg2 = *it;
    if (seg2.first <= seg.second) {
      seg.first = seg2.first;
      seg.second = min(seg.second, seg2.second);
    } else {
      ans.push_back(seg);
      seg = seg2;
    }
  }
  ans.push_back(seg);
  cout << ans.size() << endl;
  for (const auto s : ans) cout << s.second << endl;
}
