import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    N, X = map(int, input().split())

    if X * 2 > N:
        print(2 * X / (N - X))
    elif X * 2 == N:
        print(3 * X)
    else:
        print(4 * (N - X))

sol()