#include <bits/stdc++.h>
struct node {
  int x, y;
} a[2000];
int cmp(const void *a, const void *b) {
  struct node *aa = (struct node *)a;
  struct node *bb = (struct node *)b;
  return aa->y - bb->y;
}
int main(void) {
  int i, n, pre, ans, tem;
  int b[2000];
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &a[i].x, &a[i].y);
    if (a[i].x > a[i].y) {
      tem = a[i].x;
      a[i].x = a[i].y;
      a[i].y = tem;
    }
  }
  qsort(a + 1, n, sizeof(a[0]), cmp);
  for (i = 1, pre = -10001, ans = 0; i <= n; i++) {
    if (a[i].x > pre) pre = b[++ans] = a[i].y;
  }
  printf("%d\n", ans);
  for (i = 1; i <= ans; i++) printf("%d%c", b[i], i == ans ? '\n' : ' ');
  return 0;
}
