#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 200004;
vector<int> rs;
set<pair<int, int> > st, en;
int main() {
  int n, s, e;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> s >> e;
    if (s > e) swap(s, e);
    st.insert(pair<int, int>(s, e));
    en.insert(pair<int, int>(e, s));
  }
  while (!en.empty()) {
    auto it = en.begin();
    int ep = it->first;
    rs.push_back(ep);
    while (!st.empty()) {
      auto kt = st.begin();
      if (kt->first > ep) break;
      en.erase(pair<int, int>(kt->second, kt->first));
      st.erase(kt);
    }
  }
  cout << rs.size() << "\n";
  for (auto it : rs) cout << it << " ";
}
