#include <bits/stdc++.h>
using namespace std;
int sum(long int a, long int b) {
  if (a == b) {
    return a;
  }
  if (a > b) {
    return sum(a - b, b) + 2 * b;
  }
  if (a < b) {
    return sum(a, b - a) + 2 * a;
  }
}
int main() {
  long int n, x;
  cin >> n >> x;
  cout << sum(x, n - x) + n << endl;
}
