#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[1010];
int ans[1010] = {-999999999};
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
    if (a[i].first < a[i].second) swap(a[i].first, a[i].second);
  }
  sort(a, a + n);
  int s = 0;
  for (int i = 0; i < n; i++) {
    if (a[i].second > ans[s]) ans[++s] = a[i].first;
  }
  cout << s << endl;
  for (int i = 1; i <= s; i++) {
    cout << ans[i] << ' ';
  }
  cout << endl;
  return 0;
}
