#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<pair<int, int> > V(n);
  for (register int i = (0); i < (int)n; ++i) {
    cin >> V[i].second >> V[i].first;
    if (V[i].second > V[i].first) swap(V[i].second, V[i].first);
  }
  int last = -100000;
  sort((V).begin(), (V).end());
  vector<int> res;
  for (register int i = (0); i < (int)n; ++i) {
    if (V[i].second <= last) continue;
    last = V[i].first;
    res.push_back(last);
  }
  cout << ((int)(res).size()) << endl;
  for (register int i = (0); i < (int)((int)(res).size()); ++i) {
    if (i) cout << " ";
    cout << res[i];
  }
  cout << endl;
  return 0;
}
