#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  int ans = 0;
  double mid = (double)n / 2;
  if (x != mid) {
    ans = 3 * x + 2 * (n - x);
  } else {
    ans = 3 * x;
  }
  cout << ans << endl;
}
