using System;
using System.Linq;
namespace ProgrammingContest_CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            int N = A[0];
            int X = A[1];
            int a = N - 2 * X;
            if (a == 0)
            {
                Console.WriteLine(3 * X);
            }
            if (a > 0&& N < 3 * X)
            {
                int large = 3 * X;
                int small = 3 * a;
                Console.WriteLine(large + (X / a) * small);
            }
            else
            {
                Console.WriteLine(3*X);
            }
        }
    }
}