#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, x;
  cin >> n >> x;
  int ans = 0;
  int nx = n - x;
  while (nx > 1 && x > 1) {
    if (nx > x) {
      ans += x * 3;
      nx -= x;
    } else if (nx < x) {
      ans += nx * 3;
      x -= nx;
    } else {
      ans += x * 3;
      nx = 0;
      x = 0;
    }
  }
  cout << ans + nx * x * 3 << endl;
  return 0;
}
