#include <bits/stdc++.h>
using namespace std;
long long n;
long long arr[1666666];
signed main() {
  long long n, x;
  cin >> n >> x;
  long long ans = n;
  long long t1 = (n - x) / x;
  ans += t1 * x;
  long long num = n - x - x * t1;
  ans += num * (1 + (x / num) * 2);
  cout << ans;
  return 0;
}
