#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, X;
  cin >> N >> X;
  long long Line = (N - 1) * 3;
  long long kyori = min(N - X, X);
  if (N % X == 0) {
    cout << Line - (kyori - 1) * 3 << endl;
  } else {
    cout << Line << endl;
  }
}
