#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
vector<pair<long long, long long> > v;
bool cmp(pair<long long, long long> x, pair<long long, long long> y) {
  if (x.first != y.first)
    return x.first < y.first;
  else
    return x.second < y.second;
}
map<long long, long long> cnt;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    long long l, r;
    cin >> l >> r;
    if (l > r) swap(l, r);
    v.push_back({l, r});
  }
  sort(v.begin(), v.end(), cmp);
  v.push_back({10001, 10002});
  vector<long long> ans;
  long long c = 0;
  long long mx = 0;
  long long prev;
  for (long long i = 0; i <= n; ++i) {
    ++c;
    for (long long j = v[i].first; j <= v[i].second; ++j) {
      ++cnt[j];
      if (cnt[j] > mx) {
        mx = cnt[j];
        prev = j;
      }
    }
    if (mx < c) {
      ans.push_back(prev);
      --i;
      c = 0;
      mx = 0;
      cnt.clear();
    }
  }
  cout << ans.size() << '\n';
  for (long long x : ans) cout << x << ' ';
}
