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