#include <bits/stdc++.h>
using namespace std;
int calc(int width, int height) {
  if (height > width)
    return 2 * width + calc(width, height - width);
  else if (height < width)
    return 2 * height + calc(width - height, height);
  else
    return height;
}
int main(int argc, char *argv[]) {
  int ans = 0;
  int N, X;
  cin >> N >> X;
  ans = calc(X, N - X);
  cout << ans + N << endl;
  return 0;
}
