#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  int a = n;
  n = n - x;
  while (x != 0) {
    int t = (n / x) * 2 * x;
    a += t;
    int y = x;
    x = n % x;
    n = y;
  }
  cout << a - 1 << endl;
  return 0;
}
