#include <bits/stdc++.h>
using namespace std;
constexpr int evx[4] = {1, 0, -1, 0};
constexpr int evy[4] = {0, 1, 0, -1};
constexpr int INF = 1000000000;
constexpr int MODULO = 1000000007;
int main() {
  ios::sync_with_stdio(false);
  uint64_t n, x;
  cin >> n >> x;
  if (x * 2 < n)
    cout << 4 * (n - x) << '\n';
  else if (2 * x == n)
    cout << 2 * n / 3 << '\n';
  else
    cout << 4 * n - 3 * x << '\n';
}
