#include <bits/stdc++.h>
using namespace std;
long long a, b, cnt, tmp, k, t, d, lcm, ans, ansk;
long long E[2000020];
long long GCD(long long a, long long b) { return b == 0 ? a : GCD(b, a % b); }
long long LCM(long long a, long long b) { return a * b / GCD(a, b); }
int main() {
  cin >> a >> b;
  if (a == b) {
    printf("0");
    return 0;
  }
  if (a > b) t = b, b = a, a = t;
  d = b - a;
  for (int i = 1; i <= sqrt(d); i++)
    if (d % i == 0) {
      E[++cnt] = i;
      E[++cnt] = d / i;
      if (i * i == d) cnt--;
    }
  tmp = a % E[1];
  if (tmp == 0)
    k = 0;
  else
    k = E[1] - tmp;
  ans = LCM(a + k, b + k);
  for (int i = 2; i <= cnt; i++) {
    tmp = a % E[i];
    if (tmp == 0)
      k = 0;
    else
      k = E[i] - tmp;
    lcm = LCM(a + k, b + k);
    if (lcm < ans) ans = lcm, ansk = k;
  }
  cout << ansk;
  return 0;
}
