#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int x;
  cin >> n >> x;
  int y = n - x;
  int ans = 0;
  while (y != 0) {
    int bigger = max(x, y);
    int smaller = min(x, y);
    ans += 3 * smaller * (bigger / smaller);
    x = smaller;
    y = bigger % smaller;
  }
  cout << ans << endl;
  return 0;
}
