Consider infinite grid of unit cells. Some of those cells are planets. 

Meta-universe M = {p1, p2, ..., pk} is a set of planets. Suppose there is an infinite row or column with following two properties: 1) it doesn't contain any planet pi of meta-universe M on it; 2) there are planets of M located on both sides from this row or column. In this case we can turn the meta-universe M into two non-empty meta-universes M1 and M2 containing planets that are located on respective sides of this row or column. 

A meta-universe which can't be split using operation above is called a universe. We perform such operations until all meta-universes turn to universes.

Given positions of the planets in the original meta-universe, find the number of universes that are result of described process. It can be proved that each universe is uniquely identified not depending from order of splitting.

Input

The first line of input contains an integer n, (1 ≤ n ≤ 105), denoting the number of planets in the meta-universe.

The next n lines each contain integers xi and yi, ( - 109 ≤ xi, yi ≤ 109), denoting the coordinates of the i-th planet. All planets are located in different cells.

Output

Print the number of resulting universes.

Examples

Input

5
0 0
0 2
2 0
2 1
2 2


Output

3


Input

8
0 0
1 0
0 2
0 3
3 0
3 1
2 3
3 3


Output

1

Note

The following figure describes the first test case:

<image>
import java.util.TreeSet;
import java.util.InputMismatchException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Comparator;
import java.io.PrintWriter;
import java.util.Iterator;
import java.io.IOException;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author George Marcus
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskF solver = new TaskF();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskF {
    Comparator<int[]> compX;
    Comparator<int[]> compY;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int N = in.nextInt();

        compX = new Comparator<int[]>() {
            public int compare(int[] o1, int[] o2) {
                if (o1[0] != o2[0]) {
                    return o1[0] - o2[0];
                }
                return o1[1] - o2[1];
            }
        };
        compY = new Comparator<int[]>() {
            public int compare(int[] o1, int[] o2) {
                if (o1[1] != o2[1]) {
                    return o1[1] - o2[1];
                }
                return o1[0] - o2[0];
            }
        };

        TreeSet<int[]> byX = new TreeSet<int[]>(compX);
        TreeSet<int[]> byY = new TreeSet<int[]>(compY);
        for (int i = 0; i < N; i++) {
            int x = in.nextInt();
            int y = in.nextInt();
            byX.add(new int[] { x, y });
            byY.add(new int[] { x, y });
        }

        int ans = go(byX, byY);
        out.println(ans);
    }

    private int go(TreeSet<int[]> byX, TreeSet<int[]> byY) {
        if (byX.size() == 1) {
            return 1;
        }
        Iterator<int[]> itX = byX.iterator();
        Iterator<int[]> ritX = byX.descendingIterator();
        Iterator<int[]> itY = byY.iterator();
        Iterator<int[]> ritY = byY.descendingIterator();
        int prevLeft = Integer.MAX_VALUE;
        int prevRight = Integer.MAX_VALUE;
        int prevUp = Integer.MAX_VALUE;
        int prevDown = Integer.MAX_VALUE;

        while (itX.hasNext()) {
            int left = itX.next()[0];
            int right = ritX.next()[0];
            int down = itY.next()[1];
            int up = ritY.next()[1];

            if (prevLeft != Integer.MAX_VALUE && left - prevLeft > 1) {
                TreeSet<int[]> leftByX = new TreeSet<int[]>(compX);
                TreeSet<int[]> leftByY = new TreeSet<int[]>(compY);
                while (byX.first()[0] <= prevLeft) {
                    transfer(byX, byY, leftByX, leftByY, byX.first());
                }
                int leftAns = go(leftByX, leftByY);
                int rightAns = go(byX, byY);
                return leftAns + rightAns;
            }

            if (prevRight != Integer.MAX_VALUE && prevRight - right > 1) {
                TreeSet<int[]> rightByX = new TreeSet<int[]>(compX);
                TreeSet<int[]> rightByY = new TreeSet<int[]>(compY);
                while (byX.last()[0] >= prevRight) {
                    transfer(byX, byY, rightByX, rightByY, byX.last());
                }
                int leftAns = go(byX, byY);
                int rightAns = go(rightByX, rightByY);
                return leftAns + rightAns;
            }

            if (prevDown != Integer.MAX_VALUE && down - prevDown > 1) {
                TreeSet<int[]> downByX = new TreeSet<int[]>(compX);
                TreeSet<int[]> downByY = new TreeSet<int[]>(compY);
                while (byY.first()[1] <= prevDown) {
                    transfer(byX, byY, downByX, downByY, byY.first());
                }
                int downAns = go(downByX, downByY);
                int upAns = go(byX, byY);
                return downAns + upAns;
            }

            if (prevUp != Integer.MAX_VALUE && prevUp - up > 1) {
                TreeSet<int[]> upByX = new TreeSet<int[]>(compX);
                TreeSet<int[]> upByY = new TreeSet<int[]>(compY);
                while (byY.last()[1] >= prevUp) {
                    transfer(byX, byY, upByX, upByY, byY.last());
                }
                int downAns = go(byX, byY);
                int upAns = go(upByX, upByY);
                return downAns + upAns;
            }

            prevLeft = left;
            prevRight = right;
            prevUp = up;
            prevDown = down;
        }

        return 1;
    }

    private void transfer(TreeSet<int[]> byX, TreeSet<int[]> byY, TreeSet<int[]> byX2, TreeSet<int[]> byY2, int[] o) {
        byX.remove(o);
        byY.remove(o);
        byX2.add(o);
        byY2.add(o);
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

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

    public String nextString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));

        return res.toString();
    }

    private boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

}

