#include <bits/stdc++.h>
using namespace std;
string str;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }
int32_t main() {
  long long m, n;
  cin >> m >> n;
  long long a = max(m, n);
  long long b = min(m, n);
  long long dif = a - b;
  long long min_lcm = lcm(a, b), k1 = 0, k2 = 0, ans = 0;
  for (long long i = 1; i <= sqrt(dif); i++) {
    if (dif % i == 0) {
      k1 = i - a % i;
      k2 = (dif / i) - a % (dif / i);
      if (lcm(a + k1, b + k1) < min_lcm) {
        ans = k1;
        min_lcm = lcm(a + k1, b + k1);
      }
      if (lcm(a + k2, b + k2) < min_lcm) {
        ans = k2;
        min_lcm = lcm(a + k2, b + k2);
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
