#include <bits/stdc++.h>
using namespace std;
struct SHIT {
  int x, y;
} shit[1005];
bool cmp(SHIT a, SHIT b) { return a.y < b.y; }
vector<int> ans;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &shit[i].x, &shit[i].y);
    if (shit[i].x > shit[i].y) swap(shit[i].x, shit[i].y);
  }
  sort(shit, shit + n, cmp);
  ans.clear();
  ans.push_back(shit[0].y);
  int now = shit[0].y;
  for (int i = 1; i < n; i++) {
    if (shit[i].x <= now) continue;
    now = shit[i].y;
    ans.push_back(now);
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
  return 0;
}
