using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            // スペース区切りの整数の入力
            int[] D = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int N, a, b, l, out1;
            N = D[0];
            b = D[1];
            a = N - b;
            l = Math.Abs(N - b);

            out1 = N;

            while (l != 0)
            {
                if (a > b)
                {
                    a = a - b;
                    out1 = out1 + 2 * b;
                }
                else if(a < b)
                {
                    b = b - a;
                    out1 = out1 + 2 * a;
                }
                l = Math.Abs(b - a);
            }
            out1 = out1 + a;
            Console.WriteLine(out1);
        }
    }
}