#include <bits/stdc++.h>
using namespace std;
const int DX[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int DY[] = {0, 1, 0, -1, 1, -1, -1, 1};
const long long mod = 1000000007;
const int maxn = 1000 + 10;
vector<pair<pair<int, int>, int> > v;
int n, a, b;
int vis[maxn];
vector<int> w, ans;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    if (a > b) swap(a, b);
    v.push_back(make_pair(make_pair(a, -1), i));
    v.push_back(make_pair(make_pair(b, 1), i));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < 2 * n; i++) {
    pair<pair<int, int>, int> cur = v[i];
    if (vis[cur.second]) continue;
    if (cur.first.second == -1) {
      w.push_back(cur.second);
    } else {
      for (auto x : w) {
        vis[x] = 1;
      }
      w.clear();
      ans.push_back(cur.first.first);
    }
  }
  cout << (int)ans.size() << endl;
  for (auto x : ans) {
    cout << x << ' ';
  }
  cout << endl;
  return 0;
}
