#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);
long long n, x;
int main() {
  cin >> n >> x;
  long long ans = x;
  long long jo = x;
  long long te = n;
  long long so = n - x;
  while (1) {
    if (te == 0 || jo == 0 || so == 0) break;
    if (te == jo == so) {
      ans += te;
      break;
    }
    if (jo != te) {
      ans += te - jo;
      te = jo = min(te, jo);
    } else {
      ans += min(te, so);
      long long soso = so;
      so = min(te, so);
      te = max(te, soso);
      jo = te - so;
    }
  }
  cout << ans << endl;
}
