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