#include <bits/stdc++.h>
using namespace std;
long long a, b, mn, k;
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
void rua(long long d) {
  long long kk = (d - a % d) % d;
  long long x = (a + kk) * (b + kk) / gcd(a + kk, b + kk);
  if (x < mn || (x == mn && kk < k)) mn = x, k = kk;
}
int main() {
  scanf("%I64d%I64d", &a, &b);
  mn = a * b / gcd(a, b);
  if (a < b) swap(a, b);
  for (long long d = 1; d * d <= a - b; d++)
    if ((a - b) % d == 0) rua(d), rua((a - b) / d);
  return printf("%I64d\n", k), 0;
}
