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