#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll solve(ll h, ll w) {
  if (h < w) swap(h, w);
  ll res = 0;
  if (h % w != 0) {
    res += (h / w) * 2 * w;
    res += solve(w, h % w);
  } else {
    res += ((h / w) * 2 - 1) * w;
  }
  cout << h << ' ' << w << ' ' << res << endl;
  return res;
}
signed main() {
  ll n;
  ll x;
  while (cin >> n >> x) {
    ll h = x;
    ll w = n - x;
    cout << h + w + solve(h, w) << endl;
  }
}
