#include <bits/stdc++.h>
using namespace std;
long long n, x, ans;
void solve() {
  scanf("%lld %lld", &n, &x);
  ans = x + (n - x) + x;
  if (x != n - x) {
    ans += x;
    long long d = abs(x - (n - x));
    ans += ((2 * x) / d - 1);
  }
  printf("%lld\n", ans);
}
int main() {
  int tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
