#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef unsigned long long Long;

Long f(Long n, Long x) {
  if (x > n) {
    swap(x , n);
  }
  if (n == x) return x;
  return 2 * x + f(x, n - x);
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  Long n, x;
  cin >> n >> x;


  cout << n + f(n - x , x);

}

