#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, X;
  cin >> N >> X;
  ll ans = 3 * X + (N - X) + (X / (N - 2 * X) + 1) * (N - 2 * X);
  cout << ans << endl;
  return 0;
}
