#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;

int main(){
    long long n = 0, x = 0;
    cin >> n >> x;
    long long result = 0;
    if(n % 2 != 0)
        result = 3 * (n - 1);
    else
    {
        if(x < n / 2)
            result = 3 * (n - x);
        else
            result = 3 * x;
    }

    printf("%li\n", result);
}
