#include <bits/stdc++.h>
inline int cmp(double x, double y = 0, double tol = 1e-9) {
  return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}
typedef bool (*event_comparator)(std::pair<int, bool>, std::pair<int, bool>);
int segments[1003][2];
bool event_cmp(std::pair<int, bool> e1, std::pair<int, bool> e2) {
  int x1 = segments[e1.first][e1.second];
  int x2 = segments[e2.first][e2.second];
  return ((x1 == x2) ? (e1.second == e2.second) ? (e1.first < e2.first)
                                                : (e1.second < e2.second)
                     : (x1 < x2));
}
int main() {
  int n;
  scanf("%d", &n);
  std::set<std::pair<int, bool>, event_comparator> events(event_cmp);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", &segments[i][0], &segments[i][1]);
    std::sort(segments[i], segments[i] + 2);
    events.insert(std::pair<int, bool>(i, false));
    events.insert(std::pair<int, bool>(i, true));
  }
  std::set<int> queue;
  std::vector<int> answer;
  for (decltype((events).begin()) e = (events).begin(); e != (events).end();
       ++e) {
    if (!(e->second))
      queue.insert(e->first);
    else if (queue.count(e->first)) {
      answer.push_back(segments[e->first][e->second]);
      queue = std::set<int>();
    }
  }
  printf("%d\n", answer.size());
  for (decltype((answer).begin()) x = (answer).begin(); x != (answer).end();
       ++x)
    printf("%d ", *x);
  return 0;
}
