#include <bits/stdc++.h>
using namespace std;
int *h, *h1;
void qs(int q, int w) {
  int e = q, r = w, t = h[q + (rand() % (w - q + 1))], y;
  do {
    while (h[e] < t) e++;
    while (h[r] > t) r--;
    if (e <= r) {
      y = h[e];
      h[e] = h[r];
      h[r] = y;
      y = h1[e];
      h1[e] = h1[r];
      h1[r] = y;
      e++;
      r--;
    }
  } while (e <= r);
  if (q < r) qs(q, r);
  if (e < w) qs(e, w);
}
int main() {
  int q, w, e, r, t = 0, c = 0, v = 0, *a = new int[1000], *a1 = new int[1000],
                  *s = new int[1000], *s1 = new int[1000], f[1000];
  bool d[1000];
  cin >> q;
  for (w = 0; w < q; w++) {
    cin >> a[w] >> s[w];
    a1[w] = s1[w] = w;
    if (a[w] > s[w]) {
      e = a[w];
      a[w] = s[w];
      s[w] = e;
    }
    d[w] = 1;
  }
  h = a;
  h1 = a1;
  qs(0, q - 1);
  h = s;
  h1 = s1;
  qs(0, q - 1);
  for (; c < q;) {
    while (d[s1[v]] == 0) v++;
    r = c;
    while ((c < q) && (a[c] <= s[v])) {
      d[a1[c]] = 0;
      c++;
    }
    f[t] = s[v];
    t++;
  }
  cout << t << "\n";
  for (w = 0; w < t; w++) cout << f[w] << " ";
  return 0;
}
