#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
int N;
vector<pair<int, int> > V;
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    V.push_back({min(x, y), max(x, y)});
  }
  sort(V.begin(), V.end(), [](pair<int, int> a, pair<int, int> b) {
    if (a.second == b.second) return a.first < b.first;
    return a.second < b.second;
  });
  int lastEnd = -100001;
  vector<int> rs;
  for (auto seg : V) {
    if (seg.first > lastEnd) {
      lastEnd = seg.second;
      rs.push_back(lastEnd);
    }
  }
  cout << rs.size() << endl;
  for (auto it : rs) cout << it << " ";
  return 0;
}
