#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  long long X;
  cin >> X;
  long long sum = N;
  N -= X;
  while (N != X) {
    sum += 2 * X;
    long long tmp(N - X);
    N = tmp > X ? tmp : X;
    X = tmp > X ? X : tmp;
  }
  sum += X;
  cout << sum << endl;
  return 0;
}
