#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> v;
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.second == b.second) return (a.first < b.first);
  return (a.second < b.second);
}
void out(vector<pair<int, int>> v) {
  cout << endl;
  for (auto i : v) cout << i.first << " " << i.second << endl;
}
void sort(vector<pair<int, int>> &v) { sort(v.begin(), v.end(), cmp); }
int main() {
  int N;
  cin >> N;
  int i, j;
  int count = 0;
  while (N > 0) {
    cin >> i >> j;
    if (i > j) swap(i, j);
    v.push_back(make_pair(i, j));
    count++;
    N--;
  }
  sort(v);
  int answer = 0;
  vector<int> answers;
  for (auto i : v) {
    if (answer == 0 || i.first > *(answers.end() - 1)) {
      answers.push_back(i.second);
      answer++;
    }
  }
  cout << answer << endl;
  for (auto i : answers) cout << i << " ";
  return 0;
}
