#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  i64 sum(0);
  int a, b;
  cin >> a >> b;
  while (a && b) {
    if (a > b)
      sum += 2 * b, a -= b;
    else
      sum += 2 * a, b -= a;
  }
  cout << sum << endl;
  return 0;
}
