#include <bits/stdc++.h>
using namespace std;
int func(int &a, int &b) {
  int ans = 2 * a;
  int tmp = b - a;
  b = a;
  a = tmp;
  return ans;
}
int main() {
  int n, x;
  cin >> n >> x;
  int ans = n;
  int b = n - x;
  while ((b - x) > 0) {
    ans += func(x, b);
  }
  cout << (ans + x) << endl;
  return 0;
}
