#include <bits/stdc++.h>
using namespace std;
long long N, X;
int main() {
  cin >> N >> X;
  long long ans = 0;
  X = min(X, (N / 2));
  if ((N - X) % X == 0) {
    ans = (N - X) * 3;
  } else {
    long long R = (N - X) % X;
    ans = X * 3 + (N - X - R) * 3;
  }
  cout << ans << endl;
  return 0;
}
