Two friends named Jessa and Jecci has established their base camps for trekking at different places. Now they want to form a network that is they want that all their bases should be reachable from every base. One base is reachable from other base if there is a path of tunnels connecting bases. Bases are suppose based on 2-D plane having integer coordinates. Cost of building tunnels between two bases having integer coordinates (x1,y1) and (x2,y2)is min(|x1-x2|,|y1-y2|).
What is the minimum cost such that a network is formed?
Input:
First line contains N the number of bases.
Each of next N lines contains two integers xi and yi.
Output:
Print the minimum cost of building the network.
Constraints:
1<=N<=100000
-10^9<=xi, yi <=10^9