#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int x;
  cin >> n;
  cin >> x;
  int ret = 0;
  int loop = 1;
  int max0 = max(x, n - x);
  int min0 = min(x, n - x);
  ret += x + n - x;
  while (1) {
    if (max0 == min0) {
      ret += min0;
      cout << ret << endl;
      break;
    } else {
      ret += 2 * min0;
      int maxtmp = max0 - min0;
      int mintmp = min0;
      max0 = max(maxtmp, mintmp);
      min0 = min(maxtmp, mintmp);
    }
  }
}
