#include<string.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<math.h>
using namespace std;
int main() {
	unsigned long long n, x;
	cin >> n >> x;
	if (n / 2.0  != x) {
		int a = (n - x) / x;
		int b = (n - x) % x;
		cout << x * 3 * ( b + a);
	}	}else {
		cout << x * 3;
	}
	return 0;
}