#include <bits/stdc++.h>
using namespace std;
bool ignore[1024];
int main() {
  int N;
  cin >> N;
  vector<tuple<int, int, int> > v(2 * N);
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    if (x > y) swap(x, y);
    v[2 * i] = make_tuple(x, 0, i);
    v[2 * i + 1] = make_tuple(y, 1, i);
  }
  sort(v.begin(), v.end());
  vector<int> locs;
  set<int> activ;
  int idx = 0;
  while (idx < v.size()) {
    int st = get<0>(v[idx]);
    while (idx < v.size() && get<0>(v[idx]) == st) {
      if (get<1>(v[idx]) == 0)
        activ.insert(get<2>(v[idx]));
      else if (activ.count(get<2>(v[idx])) == 1) {
        locs.push_back(st);
        activ.clear();
      }
      idx += 1;
    }
  }
  cout << locs.size() << endl;
  for (auto x : locs) cout << x << " ";
  cout << endl;
  return 0;
}
