#include <bits/stdc++.h>
using namespace std;
template <typename T>
T Gmax(T a, T b) {
  return a > b ? a : b;
}
template <typename T>
T Gmin(T a, T b) {
  return a < b ? a : b;
}
const int N = 100005;
struct node {
  int x, y;
} p[1001];
bool cmp(node a, node b) {
  if (a.y != b.y) {
    return a.y < b.y;
  } else {
    return a.x < b.x;
  }
}
int main() {
  int n, a, b;
  int res[1001];
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a, &b);
    p[i].x = min(a, b);
    p[i].y = max(a, b);
  }
  sort(p + 1, p + n + 1, cmp);
  int ans = 1;
  int t = p[1].y;
  res[0] = p[1].y;
  int k = 1;
  for (int i = 2; i <= n; i++) {
    if (p[i].x > t) {
      t = p[i].y;
      ans++;
      res[k++] = t;
    }
  }
  printf("%d\n", ans);
  for (int i = 0; i < k; i++) {
    printf("%d ", res[i]);
  }
  return 0;
}
