#include <bits/stdc++.h>
void swap(int &a, int &b) {
  int t;
  t = a;
  a = b;
  b = t;
}
int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  int ans = n;
  int a = x, b = n - x;
  while (a && b) {
    if (a > b) swap(a, b);
    ans += a << 1;
    b = b - a;
  }
  ans -= a;
  printf("%d\n", ans);
  return 0;
}
