#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int> a, pair<int, int> b) {
  return a.second < b.second || (a.second == b.second && a.first < b.first);
}
void solve() {
  int n;
  cin >> n;
  vector<pair<int, int>> s;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    s.emplace_back(a, b);
  }
  sort(s.begin(), s.end(), cmp);
  int ls = -20000;
  vector<int> ans;
  for (auto p : s) {
    int a = p.first, b = p.second;
    if (a <= ls) {
      continue;
    } else {
      ls = b;
      ans.push_back(b);
    }
  }
  cout << ans.size() << '\n';
  for (int p : ans) cout << p << " ";
  cout << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
