#include <bits/stdc++.h>
int main(void) {
  int n, x, a, b, k, ans = 0;
  scanf("%d%d", &n, &x);
  a = (x * 2 < n) ? x : n - x;
  b = n - a;
  while (a) {
    ans += a;
    if (a * 2 > b) {
      k = a;
      a = b - a;
      b = k;
    } else {
      b -= a;
    }
  }
  printf("%d", ans * 3);
  return 0;
}
