#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, INF = 1e9;
using vi = vector<long long>;
using vvi = vector<vi>;
signed main() {
  long long n, x;
  cin >> n >> x;
  if (n == 2 * x)
    cout << 3 * x << endl;
  else if (n % x == 0)
    cout << n + n - x + n - 2 * x << endl;
  else
    cout << n + n - 1 + n - 2 << endl;
}
