#include <bits/stdc++.h>
using namespace std;
struct point {
  int id, p;
  bool left;
  point(int _id, int _p, bool f) {
    id = _id;
    p = _p;
    left = f;
  }
  bool operator<(const point &x) const {
    if (p != x.p) return p < x.p;
    if (left != x.left) return left;
    return id < x.id;
  }
};
vector<point> v;
bool marked[1005];
int main() {
  int N, x, y;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x >> y;
    if (x > y) swap(x, y);
    v.push_back(point(i, x, 1));
    v.push_back(point(i, y, 0));
  }
  sort(v.begin(), v.end());
  stack<point> st;
  vector<int> ans;
  for (int i = 0; i < (int)v.size(); i++) {
    if (marked[v[i].id]) continue;
    if (v[i].left) {
      st.push(v[i]);
    } else {
      ans.push_back(v[i].p);
      while (!st.empty()) {
        marked[st.top().id] = 1;
        st.pop();
      }
    }
  }
  cout << (int)ans.size() << endl;
  for (int i = 0; i < (int)ans.size(); i++) cout << ans[i] << " ";
  return 0;
}
