from operator import truediv


n_volcanoes = int(input())

volcanoes = []
for _ in range(n_volcanoes):
    l = input().split(" ")
    x, y = l
    x = int(x)
    y = int(y)
    volcanoes.append([x, y])


xminimal = 9999999
yminimal = 9999999
startIndex = -1
for i, (x, y) in enumerate(volcanoes):
    if xminimal > x or xminimal == x and yminimal > y:
        xminimal = x
        yminimal = y
        startIndex = i

x = volcanoes[startIndex][0]
y = volcanoes[startIndex][1]

def isUp(volcanoes, x, y):
    for v in volcanoes:
        if v[0] == x and v[1] > y:
            return True
    return False
def isDown(volcanoes, x, y):
    for v in volcanoes:
        if v[0] == x and v[1] < y:
            return True
    return False

def isOn(volcanoes, x, y):
    for i, v in enumerate(volcanoes):
        if v[0] == x and v[1] == y:
            return i
    return -1

moves = 0
while True:
    is_on = isOn(volcanoes, x, y)
    if is_on != -1:
        del volcanoes[is_on]

   
    if len(volcanoes) == 0:
        break


    if isUp(volcanoes, x, y):
        y += 1
    elif isDown(volcanoes, x, y):
        y -= 1
    else: # is right
        x += 1
    
    moves+=1

    
print(moves)