#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x, ans;
  cin >> n >> x;
  if (n % x == 0) {
    ans = 3 * (n - x);
  } else if (x < (n + 1) / 2) {
    ans = 4 * (n - x);
  } else {
    ans = 6 * (n - x);
  }
  cout << ans << "\n";
}
