#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int maxn = 405;
const long long mod = 1000000007;
const double PI = acos(-1.0);
long long n, x;
void solve() {
  if (x % (n - x) == 0 && x * 2LL >= n) {
    printf("%lld\n", 3LL * x);
  } else if ((n - x) % x == 0 && x * 3LL <= n) {
    printf("%lld\n", 3LL * (n - x));
  } else {
    printf("%lld\n", 6LL * x);
  }
}
int main() {
  while (cin >> n >> x) {
    solve();
  }
  return 0;
}
