#include <bits/stdc++.h>
using namespace std;
void FastInOut() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
}
bool MySort(const pair<int, int>& A, const pair<int, int>& B) {
  return A.second < B.second;
}
int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> V;
  for (int i = 0; i < N; i++) {
    int A, B;
    cin >> A >> B;
    if (A > B) swap(A, B);
    V.push_back(make_pair(A, B));
  }
  sort(V.begin(), V.end(), MySort);
  int Last = INT_MIN;
  vector<int> Ans;
  for (int i = 0; i < N; i++) {
    if (V[i].first > Last) {
      Ans.push_back(V[i].second);
      Last = V[i].second;
    }
  }
  cout << Ans.size() << endl;
  for (auto X : Ans) cout << X << " ";
  return 0;
}
