#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

int main() {
#ifdef HOME
	freopen("agc1b.in", "r", stdin);
	freopen("agc1b.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	i64 sum(0);
	int a, b;

	cin >> a >> b;
	a = a - b;

	sum = a + b;
	while (a && b) {
		if (a > b)
			sum+= a / b * b * 2, a%= b;
		else
			sum+= b / a * a * l, b%= a; }

	cout << sum - a - b << endl;

	return 0; }
