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