#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const long double PI = acos((long double)-1);
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
long long a, b, x;
long long Lcm = 10e8 * 10e8;
long long ans = 10e8;
int main() {
  scanf("%d%d", &a, &b);
  if (b % a == 0 || a % b == 0) printf("%d ", 0), exit(0);
  long long x = abs(a - b);
  for (int i = 1; i * i <= x; i++) {
    long long k;
    if (x % i == 0) {
      if (a % i)
        k = i - a % i;
      else
        k = 0;
      long long res = (a + k) * (b + k) / i;
      if (res < Lcm) Lcm = res, ans = k;
      if (res == Lcm) ans = min(k, ans);
      if (a % (x / i))
        k = x / i - a % (x / i);
      else
        k = 0;
      res = (a + k) * (b + k) / (x / i);
      if (res < Lcm) Lcm = res, ans = k;
      if (res == Lcm) ans = min(k, ans);
    }
  }
  cout << ans;
  return 0;
}
