#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x, res;
  cin >> n >> x;
  if (n % x == 0)
    cout << (n - x) * 3 << endl;
  else
    cout << (n - x) * 4 << endl;
  return 0;
}
