N, X = map(int, input().split(" "))
ans = N
N -= X
while(True):
  if N%X==0:
    ans += (N*2-X)
    break
  else:
    ans += X*2
    N = N - X
    if N < X:
      tmp = N
      N = X
      X = tmp

print(ans)