def solve(s, a, b):
    if a == 1:
        return s + b * 2 - 1
    if b == 1:
        return s + a * 2 - 1
    if a == b:
        return s + a
    elif a > b:
        return solve(s + b * 2, a - b, b)
    else:
        return solve(s + a * 2, a, b - a)

n, x = map(int, input().split())
print(solve(n, n - x, x))