#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, x;
  bool is_trap = false;
  cin >> n >> x;
  int a = x, b = n, c = n - x;
  int ans = x;
  int ul, s;
  while (a != 0) {
    if (is_trap) {
      ans += ul;
      a = s - ul;
      b = s;
      c = ul;
      is_trap = false;
    } else {
      ans += c;
      ul = b - c;
      s = c;
      is_trap = true;
    }
  }
  cout << ans << endl;
  return 0;
}
