#include <bits/stdc++.h>
using namespace std;
long long n, x;
int main() {
  scanf("%lld%lld", &n, &x);
  if (n <= 2 * x)
    printf("%lld", 3LL * x);
  else if (n <= 3 * x)
    printf("%lld", 6LL * x);
  else
    printf("%lld", 3 * (n - x));
  return 0;
}
