using System;

namespace Mysterious_Light
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int n = int.Parse(str[0]);
            int x = int.Parse(str[1]);
            if(n%2==0)
            {
                if(x<n/2)
                {
                    x=n - x;
                }
            }
            else
            {
                x = n - 1;
            }
            Console.WriteLine(x * 3);
        }
    }
}