#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
int main() {
  long double a, b;
  cin >> a >> b;
  if (a > b) {
    long double temp = b;
    b = a;
    a = temp;
  }
  if (a == b)
    cout << 0;
  else {
    long double m = ceil(a / (b - a));
    long double ans = m * (b - a);
    long long int ind = ans - a,
                  mina = ((a + ind) * (b + ind)) / (gcd(a + ind, b + ind));
    for (int i = 1; i * i <= b - a; i++) {
      int q = a, w = b;
      if ((w - q) % i == 0) {
        long double x = i;
        m = ceil(a / x);
        ans = m * (x);
        ans = ans - a;
        long long int aa = (a + ans) * (b + ans) / (gcd(a + ans, b + ans));
        if (mina > aa) {
          mina = aa;
          ind = ans;
        }
        x = (b - a) / i;
        m = ceil(a / x);
        ans = m * (x);
        ans = ans - a;
        aa = (a + ans) * (b + ans) / (gcd(a + ans, b + ans));
        if (mina > aa) {
          mina = aa;
          ind = ans;
        }
      }
    }
    cout << ind;
  }
}
