#include <bits/stdc++.h>
using namespace std;
const int maxn = 500005;
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = (s << 1) + (s << 3) + ch - '0';
    ch = getchar();
  }
  return s * w;
}
namespace OPT {
char opt[50];
}
inline void pt(long long x) {
  int top = 0;
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  do OPT::opt[++top] = x % 10 + '0';
  while (x /= 10);
  while (top) putchar(OPT::opt[top--]);
}
struct node {
  int l;
  int r;
} a[maxn];
bool cmp(node x, node y) { return x.r < y.r; }
int kk[maxn];
int main() {
  int n = read();
  for (int i = 1; i <= n; i++) {
    int l = read();
    int r = read();
    if (l > r) swap(l, r);
    a[i].l = l;
    a[i].r = r;
  }
  sort(a + 1, a + n + 1, cmp);
  int k = 0;
  int la = a[1].r;
  k++;
  kk[k] = la;
  for (int i = 2; i <= n; i++) {
    if (a[i].l <= la && a[i].r >= la) continue;
    if (a[i].l > la) {
      la = a[i].r;
      k++;
      kk[k] = la;
      continue;
    }
    if (a[i].r < la) {
      la = a[i].r;
      kk[k] = la;
      continue;
    }
  }
  printf("%d\n", k);
  for (int i = 1; i <= k; i++) {
    printf("%d ", kk[i]);
  }
}
