In a city inhabited by the Greek gods, the streets form a grid of integer coordinates, with every street parallel to the $x$-axis or the $y$-axis. For every integer $Z$ there is a horizontal street at $y = Z$ and a vertical street at $x = Z$, so every pair of integer coordinates is a street junction. The gods rest in cafeterias located at these junctions. The messenger Hermes must deliver photon messages to the gods, moving only along the streets. Each message is addressed to a single god; it does not matter whether other gods see it.
The messages must be delivered in the given order, and Hermes receives the cafeteria coordinates in that order. Hermes starts at $(0, 0)$. To deliver the message for the cafeteria at $(X_i, Y_i)$, Hermes only needs to reach some point on the same horizontal street ($y = Y_i$) or on the same vertical street ($x = X_i$). After delivering every message, Hermes stops.
Given the sequence of cafeterias, write a program that computes the minimum total distance Hermes must travel to deliver all of the messages.
The first line contains one integer $N$, the number of messages to deliver. Each of the next $N$ lines contains the coordinates of the junction for one message, in delivery order. Each line contains two integers $X_i$ and $Y_i$ (the $x$-coordinate first, then the $y$-coordinate), separated by a space.
Print a single integer: the minimum total distance Hermes must travel to deliver all of the messages.