#include <bits/stdc++.h>
using namespace std;
int n, x, y;
bool v[1002];
vector<pair<pair<int, int>, int>> a;
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (int)(n); ++i) {
    scanf("%d %d", &x, &y);
    if (x > y) swap(x, y);
    a.push_back(make_pair(make_pair(x, 0), i)),
        a.push_back(make_pair(make_pair(y, 1), i));
  }
  sort(a.begin(), a.end());
  vector<int> curr, nails;
  for (auto p : a)
    if (!v[p.second]) {
      if (p.first.second) {
        nails.push_back(p.first.first);
        for (int second : curr) v[second] = true;
        curr.clear();
      } else
        curr.push_back(p.second);
    }
  cout << (((int)(nails).size())) << endl;
  for (int p : nails) printf("%d ", p);
}
