#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > V(n);
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    V[i] = pair<int, int>(min(x, y), max(x, y));
  }
  sort(V.begin(), V.end());
  vector<int> A;
  int i = n - 1;
  while (i >= 0) {
    int x = V[i].first;
    A.push_back(x);
    while (--i >= 0 and V[i].second >= x)
      ;
  }
  int res = A.size();
  cout << res << endl;
  for (int i = 0; i < res; ++i) cout << (i ? " " : "") << A[i];
  cout << endl;
}
