#include <bits/stdc++.h>
using namespace std;
long long Ans = 0;
void Solve(long long n, long long x) {
  if (n <= x) return;
  Ans += n + x;
  Solve(n - x, x);
}
int main() {
  long long n, x;
  scanf("%lld%lld", &n, &x);
  Solve(n, x);
  printf("%lld\n", Ans);
  return 0;
}
