#include <bits/stdc++.h>
using namespace std;
int main() {
  double n, x;
  cin >> n >> x;
  double ans = n;
  double a = x;
  double b = n - x;
  while (a != b) {
    if (a > b) {
      double tmp = a;
      a = b;
      b = tmp;
    }
    ans += 2 * a;
    b -= a;
  }
  ans += a;
  cout << ans << endl;
}
