#include <bits/stdc++.h>
using namespace std;
int main() {
  long double N, X;
  unsigned long long ans;
  cin >> N >> X;
  ans = 2 * X + (N - X) + (N - 2 * X) * 3 + 2 * (N - 2 * X);
  cout << ans << endl;
}
