#include <bits/stdc++.h>
using namespace std;
bool _cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
int main() {
  int n, x, y;
  scanf("%d", &n);
  vector<pair<int, int> > V(n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &x, &y);
    V[i].first = min(x, y);
    V[i].second = max(x, y);
  }
  sort(V.begin(), V.end(), _cmp);
  bool U[n];
  memset(U, false, sizeof U);
  vector<int> Res;
  for (int i = 0; i < n; i++) {
    if (U[i]) continue;
    Res.push_back(V[i].second);
    for (int j = i + 1; j < n; j++)
      if (V[j].first <= V[i].second) U[j] = true;
  }
  printf("%d\n", Res.size());
  for (int i = 0; i < Res.size(); i++)
    printf("%s%d", (i == 0 ? "" : " "), Res[i]);
  return 0;
}
