#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <typename Type>
Type gcd(const Type& a, const Type& b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename Type>
Type lcm(const Type& a, const Type& b) {
  return a / gcd(a, b) * b;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  ll a, b, x, t, l, k, mn;
  cin >> a >> b;
  if (a > b) swap(a, b);
  x = b - a, k = 0, mn = 1e18 + 5;
  for (ll i = 1; i * i <= x; i++) {
    if (x % i) continue;
    for (auto divi : {i, x / i}) {
      t = a % divi == 0 ? 0 : divi - a % divi;
      l = lcm(a + t, b + t);
      if (ckmin(mn, l)) k = t;
    }
  }
  cout << k << endl;
  return 0;
}
