#include <bits/stdc++.h>
using namespace std;
int a, b, i, ans, n, k, l, o, p;
vector<pair<int, int> > v;
vector<int> z;
int main() {
  cin >> n;
  z.push_back(-10001);
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    v.push_back(make_pair(max(a, b), min(a, b)));
  }
  sort(v.begin(), v.end());
  for (i = 0; i < n; i++)
    if (v[i].second > z[z.size() - 1]) z.push_back(v[i].first);
  cout << z.size() - 1 << endl;
  for (i = 1; i < z.size(); i++) cout << z[i] << " ";
}
