#include <bits/stdc++.h>
using namespace std;
int main() {
  long N, X;
  cin >> N >> X;
  long ans = 0, a, b;
  a = N - X;
  b = X;
  ans += N;
  while (true) {
    if (a == b) {
      ans += a;
      break;
    } else if (a > b) {
      ans += b * 2;
      a = a - b;
    } else {
      ans += a * 2;
      b = b - a;
    }
  }
  cout << ans << endl;
  return 0;
}
