#include <bits/stdc++.h>
const int MAXN = 1e6 + 10;
const double eps = 1e-8;
const int mod = 1e9 + 7;
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
int n;
typedef struct node {
  int x, y;
  friend bool operator<(node aa, node bb) {
    if (aa.x == bb.x) return aa.y < bb.y;
    return aa.x < bb.x;
  }
} node;
node d[MAXN];
vector<int> vec;
int main() {
  n = read();
  for (int i = 1; i <= n; i++) d[i].x = read(), d[i].y = read();
  for (int i = 1; i <= n; i++)
    if (d[i].x > d[i].y) swap(d[i].x, d[i].y);
  sort(d + 1, d + n + 1);
  int x = d[1].x;
  int y = d[1].y;
  for (int i = 2; i <= n; i++) {
    int x1 = max(x, d[i].x);
    int y1 = min(y, d[i].y);
    if (x1 > y1)
      vec.push_back(y), x = d[i].x, y = d[i].y;
    else
      x = x1, y = y1;
  }
  vec.push_back(y);
  printf("%d\n", vec.size());
  for (int i = 0; i < vec.size(); i++) printf("%d ", vec[i]);
  printf("\n");
  return 0;
}
