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