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