#include <bits/stdc++.h>
using namespace std;
const long long LLINF = (1LL << 60);
const long long INF = (1LL << 30);
const long long MOD = 1000000007;
long long N, X;
signed main() {
  cin >> N >> X;
  long long a = min(X, N - X);
  long long b = max(X, N - X);
  if (N % 2 == 0) {
    long long ans = a + b + (b / a) * 2 * a - a;
    printf("%lld\n", ans);
  } else {
    long long ans = a + b + (b / a) * 2 * a + 2 * a - 1;
    printf("%lld\n", ans);
  }
  return 0;
}
