#include <bits/stdc++.h>
using namespace std;
int n, i, j, ans, b[2011], k, anse[2011];
pair<int, pair<int, int> > a[2011];
queue<int> q;
int main() {
  cin >> n;
  for (i = 0; i < 2 * n; i += 2) {
    cin >> a[i].first >> a[i + 1].first;
    if (a[i].first > a[i + 1].first) swap(a[i].first, a[i + 1].first);
    a[i].second.first = 0;
    a[i + 1].second.first = 1;
    a[i].second.second = i / 2;
    a[i + 1].second.second = i / 2;
  }
  sort(a, a + 2 * n);
  for (i = 0; i < 2 * n; i++) {
    if (a[i].second.first == 0) {
      q.push(a[i].second.second);
    } else if (a[i].second.first == 1 && b[a[i].second.second] == 0) {
      anse[k] = a[i].first;
      k++;
      b[a[i].second.second] = 1;
      ans++;
      while (q.size() > 0) {
        b[q.front()] = 1;
        q.pop();
      }
    }
  }
  cout << ans << endl;
  for (i = 0; i < k; i++) cout << anse[i] << " ";
}
