import java.lang.Math.*
fun main(args:Array<String>?): Unit {
    val n = readLine()!!.trim().toInt()
    val coinCount = Array(2){IntArray(n){0}}
    var currentCost = 0L
    repeat(2 * n){
        val (x, y) = readLine()!!.trim().split(' ').map(String::toInt)
        if (x in 1 .. n) {
            if (y <= 1) {
                currentCost += 1 - y
                coinCount[0][x - 1]++
            }else {
                currentCost += y - 2
                coinCount[1][x - 1]++
            }
        }else {
            if (x <= 1){
                currentCost += 1 - x
                if (y <= 1){
                    currentCost += 1 - y
                    coinCount[0][0]++
                }else {
                    currentCost += y - 2
                    coinCount[1][0]++
                }
            }else {
                currentCost += x - n
                if (y <= 1){
                    currentCost += 1 - y
                    coinCount[0][n - 1]++
                }else {
                    currentCost += y - 2
                    coinCount[1][n - 1]++
                }
            }
        }
    }
    for (i in 0 until n - 1){
        if (coinCount[0][i] <= 0) {
            if (coinCount[1][i] > 1) {
                val move = min(1 - coinCount[0][i], coinCount[1][i] - 1)
                currentCost += move
                coinCount[0][i] += move
                coinCount[1][i] -= move
            }
            currentCost += 1 - coinCount[0][i]
            coinCount[0][i + 1] -= 1 - coinCount[0][i]
            coinCount[0][i] = 1
        }
        if (coinCount[1][i] <= 0){
            if (coinCount[0][i] > 1){
                val move = min(1 - coinCount[1][i], coinCount[0][i] - 1)
                currentCost += move
                coinCount[1][i] += move
                coinCount[0][i] -= move
            }
            currentCost += 1 - coinCount[1][i]
            coinCount[1][i + 1] -= 1 - coinCount[1][i]
            coinCount[1][i] = 1
        }
        if (coinCount[0][i] > 1){
            currentCost += coinCount[0][i] - 1
            coinCount[0][i + 1] += coinCount[0][i] - 1
            coinCount[0][i] = 1
        }
        if (coinCount[1][i] > 1) {
            currentCost += coinCount[1][i] - 1
            coinCount[1][i + 1] += coinCount[1][i] - 1
            coinCount[1][i] = 1
        }
    }
    currentCost += abs(coinCount[0].last() - 1)
    println(currentCost)
}
