#include<bits/stdc++.h>
using namespace std;
#define LINE 8
#define st 1
#define YOKO 17
int main(){
    long long N,X;
    cin>>N>>x;
        if(X==N/2){
            cout<<3*X;
        }else if(X>=N/2){
            cout<<3/2*X+N;
        }else{
            cout<<(X+N)*X/(N-X)+N;
        }
    return 0;
}
