#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, i;
  cin >> n;
  vector<pair<int, int> > v(n);
  for (i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v[i].first = max(x, y);
    v[i].second = min(x, y);
  }
  sort(v.begin(), v.end());
  vector<int> ans;
  ans.push_back(v[0].first);
  int temp = v[0].first;
  for (i = 1; i < n; i++) {
    if (v[i].second > temp) {
      temp = v[i].first;
      ans.push_back(temp);
    }
  }
  cout << ans.size() << "\n";
  for (i = 0; i < ans.size(); i++) cout << ans[i] << " ";
}
