#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
ll f(int a, int b) {
  if (b <= 0) return 0;
  ll ans = 2 * a + f(a, b - a);
  return ans;
}
ll solve(int a, int b) {
  ll ans = 0;
  if (a < b)
    return ans += f(a, b);
  else {
    ans = a + solve(a - b, b);
  }
  return ans;
}
int main() {
  int a, b;
  cin >> a >> b;
  cout << solve(a, b);
}
