#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, x, length;
  long int a[2];
  cin >> n >> x;
  a[0] = n - x;
  a[1] = x;
  length = x;
  while (a[0] * a[1] != 0) {
    if (a[0] > a[1]) {
      length = length + (a[0] / a[1]) * a[1];
      a[0] = a[0] % a[1];
    } else {
      a[1] = a[1] % a[0];
    }
  }
  cout << length * 3;
}
