#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, x, a, b, c, l;
  cin >> n >> x;
  l = n;
  a = x;
  b = n - x;
  while (1) {
    if (a == b) {
      l += a;
      break;
    }
    if (a > b) swap(a, b);
    l += a * 2;
    int t = b;
    b = a;
    a = t - a;
  }
  cout << l << endl;
  return 0;
}
