#include <bits/stdc++.h>
int main(void) {
  long long int n, x;
  long long int a, b;
  int i, j, k, l;
  int flag = 0;
  long long int ans = 0;
  int count = 0;
  int temp, temp1, temp2;
  int min;
  scanf("%lld %lld", &n, &x);
  ans = n;
  a = x;
  b = n - x;
  while (flag == 0) {
    if (a == b) {
      ans = ans + a;
      flag = 1;
    } else if (a < b) {
      ans = ans + a * 2;
      b = b - a;
    } else {
      ans = ans + b * 2;
      a = a - b;
    }
  }
  printf("%lld", ans);
  return 0;
}
