#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > a;
vector<int> result;
int main() {
  int n, i, x, y, sign = -100001, res = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    if (x > y) swap(x, y);
    a.push_back(pair<int, int>(y, x));
  }
  sort(a.begin(), a.end());
  for (i = 0; i < n; i++) {
    if (sign >= a[i].second && a[i].first >= sign) {
      continue;
    } else {
      sign = a[i].first;
      res++;
      result.push_back(a[i].first);
    }
  }
  printf("%d\n", res);
  printf("%d", result[0]);
  for (i = 1; i < res; i++) {
    printf(" %d", result[i]);
  }
  printf("\n");
  return 0;
}
