n, x = map(int, raw_input().split())
s = [x, n-x, n-x, n]
ans = x
s.sort()
while not(s[0] == s[3]):
    dup = set([x for x in s if s.count(x) > 1])
    if (len(dup) == 1):
        elem = dup.pop()
        s[3] -= elem
        ans += elem
        s.sort()
    else:
        s[2] -= s[0]
        ans += s[0]
        s.sort()
ans += s[0]
print ans
