#include <bits/stdc++.h>
using namespace std;
const int N = 10000;
pair<int, int> s[N];
int n;
bool read() {
  if (!(cin >> n)) return false;
  for (int i = 0; i < int(n); ++i) {
    cin >> s[i].second >> s[i].first;
    if (s[i].second > s[i].first) swap(s[i].second, s[i].first);
  }
  return true;
}
void solve() {
  vector<int> res;
  sort(s, s + n);
  for (int i = 0; i < int(n); ++i) {
    int last = int(res.size()) ? res.back() : -1e9;
    if (last < s[i].second) res.push_back(s[i].first);
  }
  cout << int(res.size()) << endl;
  for (int i = 0; i < int(int(res.size())); ++i) cout << res[i] << " ";
}
int main() {
  while (read()) solve();
  return 0;
}
