#include <bits/stdc++.h>
using namespace std;
int min(int n, int x) { return (x < n - x) ? x : n - x; }
int main() {
  int n;
  int x;
  int len;
  cin >> n >> x;
  if (n % x != 0) {
    len = 3 * (n - 1);
  } else {
    len = 3 * (n - 1) - 3 * (min(n, x) - 1);
  }
  cout << len << endl;
}
