#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  pair<int, int> inp[n];
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    if (y < x) swap(x, y);
    inp[i].first = y;
    inp[i].second = x;
  }
  sort(inp, inp + n);
  int ls = -10005;
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    if (inp[i].second > ls) {
      ans.push_back(inp[i].first);
      ls = inp[i].first;
    }
  }
  cout << ans.size() << "\n";
  for (auto x : ans) cout << x << " ";
  return 0;
}
