using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int x = int.Parse(input[1]);
        int y = int.Parse(input[0]) - x;
        int sum = 0;
        sum += x;
        sum += y;
        while (x != 0)
        {
            sum += (2 * x) * (y / x);
            int tmp = y;
            y = x;
            x = tmp % x;
        } 
        sum -= y;
        Console.WriteLine(sum);
    }
}
