#include <bits/stdc++.h>
void move(int N, int X, int *b, int *d, int *x, int *y, int *t) {
  int ox = *x;
  int oy = *y;
  switch (*d) {
    case 0:
      b[0] = *x;
      *t += b[1];
      *y = b[1];
      *d = 2;
      break;
    case 1:
      b[1] = *y;
      *t += ((N - X) - b[0]);
      *x = b[0];
      *d = 2;
      break;
    case 2:
      *y = 0;
      *x += oy;
      *d = 0;
      *t += oy;
      if (*x > N - X) {
        *t -= (*x - (N - X));
        *y += (*x - (N - X));
        *x = N - X;
        *d = 1;
      }
      break;
  }
}
int main(int argc, char **argv) {
  int N, X;
  scanf("%d %d", &N, &X);
  int t = N;
  int x = 0, y = X;
  int d = 2;
  int b[2] = {0, X};
  while (x != N - X || y != 0) {
    move(N, X, b, &d, &x, &y, &t);
  }
  printf("%d\n", t);
  return 0;
}
