#include <bits/stdc++.h>
using namespace std;
int k = 0;
int a[1000];
struct p {
  int x, y;
} seg[1010];
int cmp(const void *a, const void *b) {
  return (*(struct p *)a).y - (*(struct p *)b).y;
}
void recursive_activity_selector(p *seg, int i, int n);
int main() {
  for (int i = 0; i < 1000; i++) {
    a[i] = 0;
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> seg[i].x >> seg[i].y;
    if (seg[i].y < seg[i].x) {
      int tmp = seg[i].x;
      seg[i].x = seg[i].y;
      seg[i].y = tmp;
    }
  }
  qsort(seg, n, sizeof(seg[0]), cmp);
  recursive_activity_selector(seg, 0, n);
  cout << k << endl;
  for (int i = 0; i < k; i++) {
    cout << a[i] << " ";
  }
}
void recursive_activity_selector(p *seg, int i, int n) {
  a[k] = seg[i].y;
  k++;
  int m = i + 1;
  while (m <= n && (seg[m].x <= seg[i].y)) {
    m++;
  }
  if (m < n) {
    recursive_activity_selector(seg, m, n);
  }
}
