#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a[100], b = 0, i = 1;
  cin >> a[0] >> a[1];
  for (;; i++) {
    a[i + 1] = a[i - 1] % a[i];
    if (a[i] < a[i + 1]) swap(a[i], a[i + 1]);
    if (a[i + 1] == 0) break;
  }
  for (long long j = 1; j < i; j++) b += a[j];
  cout << b * 3 << endl;
  return 0;
}
