using System;

namespace AGC001_B___Mysterious_Light
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solver());
        }
        static long solver()
        {
            var NX = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var N = NX[0];
            var X = NX[1];

            if (X * 2 == N) return 3 * X; else if (X * 2 > N) return 6 * N - 5 * X; else return 4 * (N - X);
        }
    }
}
