solve (n : x : _) | even n = 3 * (m + (max m x - min m x))
                  | n `mod` 3 == 0 && x `mod` 3 == 0 = 3 * (n - 3)
                  | otherwise = 3 * (n - 1)
  where m = n `div` 2

main = getLine >>= print . solve . map read . words
