#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > S;
set<int> T;
int main() {
  int n, a, b, mi, ma;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    mi = min(a, b);
    ma = max(a, b);
    S.insert(make_pair(ma, mi));
  }
  set<pair<int, int> >::iterator it;
  int ans = 1, cur = S.begin()->first;
  T.insert(cur);
  for (it = ++S.begin(); it != S.end(); it++) {
    int s = it->second, e = it->first;
    if (cur >= s && cur <= e) continue;
    cur = e;
    T.insert(cur);
    ans++;
  }
  cout << ans << endl;
  for (set<int>::iterator in = T.begin(); in != T.end(); in++) {
    cout << *(in) << " ";
  }
  cout << endl;
}
