#include <bits/stdc++.h>
using namespace std;
struct event {
  int id, x;
  bool type;
  bool operator<(const event &P) const {
    return (x < P.x) || (x == P.x && type > P.type);
  }
};
int t, n, a, b, ans, com[1012 * 2];
event X[1012 * 2];
bool used[1012];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a, &b);
    if (a > b) swap(a, b);
    X[2 * i].x = a;
    X[2 * i].type = 1;
    X[2 * i].id = i;
    X[2 * i + 1].x = b;
    X[2 * i + 1].type = 0;
    X[2 * i + 1].id = i;
  }
  n *= 2;
  sort(X, X + n);
  ans = 0;
  stack<int> s;
  memset(used, 0, sizeof(used));
  for (int i = 0; i < n; i++) {
    if (X[i].type) {
      s.push(X[i].id);
    } else if (!used[X[i].id]) {
      used[X[i].id] = 1;
      com[ans++] = X[i].x;
      for (; !s.empty(); s.pop()) {
        used[s.top()] = 1;
      }
    }
  }
  printf("%d\n", ans);
  for (int i = 0; i < ans; i++) {
    if (i) printf(" ");
    printf("%d", com[i]);
  }
  printf("\n");
  return 0;
}
