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