#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, pair<int, int> > > arr;
vector<int> ans, cur;
vector<char> used;
bool cmp(const pair<int, pair<int, int> > &a,
         const pair<int, pair<int, int> > &b) {
  if (a.second.first != b.second.first) {
    return a.second.first < b.second.first;
  }
  return a.second.second < b.second.second;
}
int main() {
  scanf("%d", &n);
  used.resize(n, false);
  arr.resize(2 * n);
  for (int i = 0; i < n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (a > b) {
      swap(a, b);
    }
    arr[2 * i].first = i;
    arr[2 * i].second.first = a;
    arr[2 * i].second.second = 1;
    arr[2 * i + 1].first = i;
    arr[2 * i + 1].second.first = b;
    arr[2 * i + 1].second.second = 2;
  }
  sort(arr.begin(), arr.end(), cmp);
  for (int i = 0; i < 2 * n; ++i) {
    if (arr[i].second.second == 1) {
      cur.push_back(arr[i].first);
    } else if (!used[arr[i].first]) {
      ans.push_back(arr[i].second.first);
      for (int i = 0; i < cur.size(); ++i) {
        used[cur[i]] = true;
      }
      cur.clear();
    }
  }
  printf("%d\n", int(ans.size()));
  for (int i = 0; i < ans.size(); ++i) {
    printf("%d ", ans[i]);
  }
  return 0;
}
