#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14

signed main(){
	int n, x;
	cin >> n >> x;


	if(n == 2 * x)
		cout << 3 * x << endl;
	else if(n % x != 0 && (n % 2 == 1 || x % 2 == 1))
		cout << n + n - 1 + n - 2 << endl;
	else{
		int amari = n % x;
		int va = n - amari;
		cout << 3 * va - 3 * amari << endl;


}
