n, x = map(int, raw_input().split())
s = [x, n-x, n-x, n]
ans = x
s.sort()
while not(s[0] == s[3]):
    if (s[1] == s[2]):
        s[3] = s[0]
        ans += s[2]
        s.sort()
    else:
        s[2] -= s[0]
        ans += s[0]
        s.sort()
ans += s[0]
print ans
