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