#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e8;
const double EPS = 1e-6;
const long long MOD = (long long)(1e5);
const long long MAXV = (long long)(1e5 + 10);
const long long MAXE = (long long)(4e5 + 10);
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first)
    return a.first < b.first;
  else
    return a.second > b.second;
}
int n;
vector<pair<int, int> > seg;
vector<int> sol;
int main() {
  scanf("%d", &n);
  for (int i = 0, a, b; i < n; i++) {
    scanf("%d%d", &a, &b);
    if (b < a) swap(a, b);
    seg.push_back(pair<int, int>(a, b));
  }
  seg.push_back(pair<int, int>(MAXV, MAXV + 1));
  n++;
  sort(seg.begin(), seg.end(), cmp);
  int a = seg[0].first;
  int b = seg[0].second;
  for (int k = 1; k < n; k++) {
    if (seg[k].first > b) {
      sol.push_back(b);
      a = seg[k].first;
      b = seg[k].second;
    } else if (seg[k].second < b)
      b = seg[k].second;
  }
  printf("%d\n", (int)sol.size());
  for (int i = 0; i < (int)sol.size(); i++) printf("%d\n", sol[i]);
  return 0;
}
