using System;
using System.Collections.Generic;

namespace agc_001
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] tmp = Console.ReadLine().Split(' ');
            int N = int.Parse(tmp[0]);
            int X = int.Parse(tmp[1]);
            int ans = 0;

            if( ((double)X) < ((double)N / 2))
            {
                ans += (N + (X*3) + (X / 2));
            }else if(((double)X) > ((double)N / 2))
            {
                ans += ((((N / (N - X)) - 1) * 2) * (N-X)) ;
                ans += X;
            }else
            {
                ans += X * 3;
            }

            Console.WriteLine(ans);
        }
    }
}
