#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e6 + 8;
const long long MOD = 1e9 + 7;
const long long sz = 1e5 + 5;
void f_io() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
}
int32_t main() {
  f_io();
  long long tc = 1;
  while (tc--) {
    long long n;
    cin >> n;
    vector<pair<pair<long long, long long>, long long>> v;
    for (long long i = 0; i < n; i++) {
      long long l, r;
      cin >> l >> r;
      if (l > r) swap(l, r);
      v.push_back({{l, -1}, i});
      v.push_back({{r, 1}, i});
    }
    bool vis[n + 1];
    memset(vis, false, sizeof vis);
    sort(begin(v), end(v));
    queue<long long> q;
    vector<long long> ret;
    vector<long long> ans;
    for (auto el : v) {
      if (el.first.second == -1) {
        q.push(el.second);
      } else {
        if (vis[el.second]) continue;
        while (!q.empty()) {
          vis[q.front()] = true;
          q.pop();
        }
        ans.push_back(el.first.first);
      }
    }
    cout << ans.size() << "\n";
    for (auto el : ans) cout << el << " ";
  }
}
