#include <bits/stdc++.h>
using namespace std;
const int nmax = 100005;
const long long mod = 1e4;
const long long inf = 1e9;
const long double EPS = 1e-2;
const long double PI = acos(-1.0);
const int kor = 320;
int a[205];
int main() {
  ios_base::sync_with_stdio(false);
  long long n, x;
  cin >> n >> x;
  if (x + x <= n) {
    long long ans = n + x;
    long long ret = n - x;
    if (ret == x) {
      cout << ans << '\n';
      return 0;
    }
    ans += x;
    if (x % (n - x - x) == 0) {
      long long tm = x / (n - x - x);
      ans += (tm + tm - 1ll) * (n - x - x);
    } else {
      long long tm = x / (n - x - x);
      ans += (tm + tm) * (n - x - x);
      ans += (n - x - x) + (n - x - x) - 1ll;
    }
    cout << ans << '\n';
  } else {
    long long ans = n;
    if (x % (n - x) == 0) {
      long long tm = x / (n - x);
      ans += (tm + tm - 1ll) * (n - x);
    } else {
      long long tm = x / (n - x);
      ans += (tm + tm) * (n - x);
      ans += (n - x) + (n - x) - 1ll;
    }
    cout << ans << '\n';
  }
  return 0;
}
