#include <bits/stdc++.h>
int main(void) {
  int i = 2;
  long long int N, X;
  scanf("%lld%lld", &N, &X);
  while (N < X * i) {
    i++;
  }
  if (N == X * i)
    printf("%lld\n", X * 3);
  else
    printf("%lld\n", (N - 1) * 3);
  return 0;
}
