#include <bits/stdc++.h>
using namespace std;
int main(void) {
  bool isDaikei = true;
  int side1, side2, side3, side4;
  int n, x;
  int length = 0;
  scanf("%d", &n);
  scanf("%d", &x);
  side1 = x;
  side2 = n;
  side3 = n - x;
  side4 = n - x;
  length = x;
  while (side2 != side3) {
    if (isDaikei) {
      side2 = side2 - side4;
      length += side4;
      isDaikei = false;
      if (side2 < side4) {
        int swp = side2;
        side2 = side4;
        side1 = side3;
        side3 = swp;
        side4 = swp;
      }
    } else {
      side1 = side1 - side4;
      length += side4;
      isDaikei = true;
    }
  }
  length += side4;
  printf("%d\n", length);
  return 0;
}
