#include <bits/stdc++.h>
using namespace std;
struct qqq {
  long long x, y;
};
qqq q[100000];
bool cmp(qqq a, qqq b) {
  if (a.y == b.y)
    return a.x < b.x;
  else
    return a.y < b.y;
}
long long n, m, i, j, l, ans, ma = -999999999, a[100000], y, x, b[100000];
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> q[i].x >> q[i].y;
    if (q[i].y < q[i].x) swap(q[i].x, q[i].y);
  }
  sort(q, q + n, cmp);
  x++;
  ma = q[0].y;
  a[0] = ma;
  l = 1;
  for (i = 1; i < n; i++) {
    if (q[i].x <= ma)
      continue;
    else {
      ma = q[i].y;
      x++;
      a[l++] = ma;
    }
  }
  cout << x << endl;
  for (i = 0; i < l; i++) {
    cout << a[i] << " ";
  }
  return 0;
}
