import std.stdio,
  std.array,
  std.range,
  std.conv,
  std.string,
  std.algorithm;

long calc(long n, long x)
{
  if (n <= x) {
    return x*2;
  }
  long res = x + (n - x);
  return res + calc(n - x, x);
}

void main()
{
  long n, x;
  readf("%d %d", &n, &x);

  writeln(calc(n, x));
}
