#include <bits/stdc++.h>
long long gcd(long long p, long long q) { return q ? gcd(q, p % q) : p; }
long long a, b, ans_k{}, ans = 0x3f3f3f3f3f3f3f3f;
long long calc(long long a, long long b) {
  if (a <= b) return b;
  if (a % b == 0) return a;
  return (a + b - a % b);
}
std::vector<long long> fac;
int main() {
  scanf("%lld%lld", &a, &b);
  if (a == b) return 0 * puts("0");
  if (a < b) std::swap(a, b);
  ans = a * b / gcd(a, b);
  long long upper = calc(b, a - b);
  for (long long i = 1; i * i <= upper; i++) {
    if (upper % i == 0) {
      fac.push_back(i);
      fac.push_back(upper / i);
    }
  }
  std::sort(fac.begin(), fac.end());
  for (auto each : fac) {
    long long buf = calc(b, each), k = buf - b;
    long long tmp = (a * b + (a + b) * k + k * k) / each;
    if (tmp < ans) {
      ans = tmp;
      ans_k = k;
    }
  }
  printf("%lld\n", ans_k);
  return 0;
}
