#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 << 21;
vector<pair<int, int> > v;
vector<int> a;
int main() {
  ios::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  ;
  a.push_back(-10001);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    if (x < y) swap(x, y);
    v.push_back({x, y});
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++)
    if (v[i].second > a.back()) a.push_back(v[i].first);
  cout << a.size() - 1 << endl;
  for (int i = 1; i < a.size(); i++) cout << a[i] << " ";
  cout << endl;
  return 0;
}
