#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
ULL solve2(ULL a, ULL b, ULL c, ULL d, ULL e, ULL f) {
  if (a == 0) return 0;
  if (c >= a)
    return b + a + solve2(c - a, d, e, f, 0, b + a);
  else
    return e + f + solve2(d - f, c, b, a, 0, e + f);
}
void solve() {
  ULL n, x;
  cin >> n >> x;
  ULL ans = x;
  ans += solve2(n - x, 0, n, 0, n - x, x);
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
