#include <bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}
using namespace std;
long long int ans = 0, sum = 0;
long long int n, x;
vector<long long int> v;
int main() {
  cin >> n >> x;
  if (n % 2) {
    cout << (n - 1) * 3 << endl;
  } else {
    x = (x > n / 2) ? n - x : x;
    cout << (n - x) * 3 << endl;
  }
}
