#include <bits/stdc++.h>
typedef struct hoge {
  int y;
  int x;
  int res;
} hoge;
void foo(hoge *a);
int main() {
  int n;
  hoge a;
  scanf("%d", &n);
  scanf("%d", &a.x);
  a.y = n - a.x;
  a.res = a.x + a.y;
  foo(&a);
  printf("%d\n", a.res);
  return 0;
}
void foo(hoge *a) {
  int swap = a->y;
  a->res += a->x * 2;
  a->y = a->x;
  a->x = swap - a->x;
  if (a->x) {
    foo(a);
  } else {
    a->res -= a->y;
  }
}
