You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is considered to be nailed too. What is the smallest number of nails needed to nail all the segments down?

Input

The first line of the input contains single integer number n (1 ≤ n ≤ 1000) — amount of segments. Following n lines contain descriptions of the segments. Each description is a pair of integer numbers — endpoints coordinates. All the coordinates don't exceed 10000 by absolute value. Segments can degenarate to points.

Output

The first line should contain one integer number — the smallest number of nails needed to nail all the segments down. The second line should contain coordinates of driven nails separated by space in any order. If the answer is not unique, output any.

Examples

Input

2
0 2
2 5


Output

1
2 

Input

5
0 3
4 2
4 8
8 10
7 7


Output

3
7 10 3
import com.sun.javafx.collections.ArrayListenerHelper;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;

public class Solution22D {
  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    Solver22D solver = new Solver22D();
    solver.solve(0, in, out);
    out.close();
  }

  static class Solver22D {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
      int n = in.nextInt();
      List<Pair> ps = new ArrayList<>();

      for (int i = 0; i < n; i++) {
        int a = in.nextInt(), b = in.nextInt();
        ps.add(new Pair(Math.min(a, b), Math.max(a, b)));
      }

      Collections.sort(ps, (o1, o2) -> {
        if (o1.l == o2.l) {
          return o1.r - o2.r;
        }
        return o1.l - o2.l;
      });

      List<List<Pair>> list = new ArrayList<>();

      for (Pair p : ps) {
        boolean added = false;
        for (int i = 0; i < list.size(); i++) {
          List<Pair> subl = list.get(i);
          if (p.l > subl.get(subl.size() - 1).r) {
            subl.add(p);
            added = true;
            break;
          }
        }
        if (!added) {
          list.add(new ArrayList<>());
          list.get(list.size() - 1).add(p);
        }
      }

      int[] ind = new int[list.size()];

      /*
      for (List<Pair> l : list) {
        out.println(l);
      }
       */

      List<Integer> res = new ArrayList<>();
      List<Pair> tmplist = new ArrayList<>();
      while (true) {
        boolean f = true;
        int l = Integer.MAX_VALUE;
        int r = Integer.MIN_VALUE;
        tmplist.clear();
        for (int i = 0; i < ind.length; i++) {
          if (ind[i] < list.get(i).size()) {
            f = false;
            l = Math.min(l, list.get(i).get(ind[i]).l);
            tmplist.add(list.get(i).get(ind[i]));
          }
        }
        if (f) {
          break;
        }
        Collections.sort(tmplist, (o1, o2) -> {
          if (o1.l == o2.l) {
            return o1.r - o2.r;
          }
          return o1.l - o2.l;
        });
        for (int i = 0; i < ind.length; i++) {
          if (ind[i] < list.get(i).size()) {
            if (l == list.get(i).get(ind[i]).l) {
              r = list.get(i).get(ind[i]).r;
            }
          }
        }
        for (int i = 0; i < tmplist.size(); i++) {
          int tmpl = Math.max(l, tmplist.get(i).l);
          int tmpr = Math.min(r, tmplist.get(i).r);
          if (tmpr >= tmpl) {
            l = tmpl;
            r = tmpr;
          }
        }
        //out.println(l + " " + r);
        res.add(l);
        for (int i = 0; i < ind.length; i++) {
          if (ind[i] < list.get(i).size()) {
            int tmpl = Math.max(l, list.get(i).get(ind[i]).l);
            int tmpr = Math.min(r, list.get(i).get(ind[i]).r);
            if (tmpr >= tmpl) {
              ind[i]++;
            }
          }
        }
      }

      out.println(res.size());
      for (int i = 0; i < res.size(); i++) {
        if (i > 0) {
          out.print(" ");
        }
        out.print(res.get(i));
      }
      out.println();
    }

    class Pair {
      int l;
      int r;

      public Pair(int l, int r) {
        this.l = l;
        this.r = r;
      }

      @Override
      public String toString() {
        return "[" + l + "," + r + "]";
      }
    }
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }
  }
}