#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int> p1, pair<int, int> p2) {
  return p1.second != p2.second ? p1.second < p2.second : p1 < p2;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, l, r, cnt = 0;
  cin >> n;
  vector<int> ans, vis(n);
  vector<pair<int, int> > v;
  for (int i = 0; i < n; ++i) {
    cin >> l >> r;
    v.push_back({min(l, r), max(l, r)});
  }
  sort(v.begin(), v.end(), cmp);
  for (int i = 0; i < n; ++i) {
    if (!vis[i]) {
      ans.push_back(v[i].second);
      for (int j = 0; j < n; ++j)
        if (v[j].first <= v[i].second && v[j].second >= v[i].second) vis[j] = 1;
    }
  }
  cout << ans.size() << '\n';
  for (auto i : ans) cout << i << " ";
}
