#include <bits/stdc++.h>
using namespace std;
long long r;
int n, k, u[1005];
struct seg {
  int x, y;
} v[1005];
int cmp(seg a, seg b) {
  if (b.y == a.y) return a.x < b.x;
  return a.y < b.y;
}
int main() {
  cin >> n;
  u[0] = -10001;
  for (int i = 1; i <= n; i++) {
    int x1, y1;
    cin >> x1 >> y1;
    if (y1 < x1) swap(x1, y1);
    v[i].x = x1, v[i].y = y1;
  }
  sort(v + 1, v + 1 + n, cmp);
  for (int i = 1; i <= n; i++)
    if (v[i].x > u[k]) u[++k] = v[i].y;
  cout << k << "\n";
  for (int i = 1; i <= k; i++) cout << u[i] << " ";
}
