

n_volcanoes = int(input())

volcanoes = {}
for _ in range(n_volcanoes):
    l = input().split(" ")
    x, y = l
    x = int(x)
    y = int(y)
    if x not in volcanoes.keys():
        volcanoes[x] = []

    volcanoes[x].append(y)


for v in volcanoes.values():
    v.sort()
#print(volcanoes)


x = min(volcanoes.keys())
y = volcanoes[x][0]
y_index = 0
for i, item in enumerate(volcanoes[x]):
    if y > item:
        y = item
        y_index = i


#print(x, y)
del volcanoes[x][y_index]
if len(volcanoes[x]) == 0:
    del volcanoes[x] 


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

def abs_min(l):
    res = 1000001
    min_index = l[0]
    for i, x in enumerate(l):
        if x < res:
            res = x
            min_index = i
    return min_index

def map_me(l, y):
    res = []
    for _y in l:
        res.append(_y - y)
    return res

def whereToMove(volcanoes, x, y):
    if x in volcanoes:
        #print("here")
        mapped = map_me(volcanoes[x], y)
        min_index = abs_min(mapped)
        #print(mapped)
        
        del volcanoes[x][min_index]
        if len(volcanoes[x]) == 0:
            del volcanoes[x] 

        return mapped[min_index] # returns the difference of _y and y

    return 0

moves = 0
while True:
    #print(x, y)

    is_on = isOn(volcanoes, x, y)

   
    if len(volcanoes) == 0:
        break


    currMov = whereToMove(volcanoes, x, y)
    if currMov!=0:
        y += currMov
    else:
        x += 1
        moves += 1

    #print(currMov)

    moves+=abs(currMov)



    

    
print(moves)