#include <bits/stdc++.h>
using namespace std;
const int N = 200020;
long long int n;
struct point {
  long long int coord;
  long long int scene;
  long long int lidx;
};
point ar[N];
long long int sz = 0;
bool comp(point a, point b) {
  if (a.coord == b.coord) {
    if (a.scene == b.scene) {
      return a.lidx < b.lidx;
    } else
      return a.scene < b.scene;
  } else
    return a.coord < b.coord;
}
vector<long long int> ans;
set<long long int> st;
int main() {
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    long long int x, y;
    cin >> x >> y;
    ar[++sz] = {min(x, y), 1, i};
    ar[++sz] = {max(x, y), 2, i};
  }
  sort(ar + 1, ar + sz + 1, comp);
  for (long long int i = 1; i <= sz; i++) {
    point x = ar[i];
    if (x.scene == 1) {
      st.insert(x.lidx);
    } else {
      if (st.find(x.lidx) != st.end()) {
        ans.push_back(x.coord);
        st.clear();
      } else
        continue;
    }
  }
  cout << ans.size() << endl;
  for (long long int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  return 0;
}
