#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  long long a, b;
  cin >> a >> b;
  if (a > b) swap(a, b);
  long long resk = 0, lcm = a * b / gcd(a, b);
  vector<long long> d;
  {
    long long k = b - a;
    for (long long i = 1; i <= k / i; ++i) {
      if (k % i == 0) {
        d.push_back(i);
        if (i * i != k) d.push_back(k / i);
      }
    }
  }
  for (long long i = 0; i < d.size(); ++i) {
    long long g = d[i];
    long long k = ((-a) % g + g) % g;
    long long nxt = (a + k) * (b + k) / g;
    if (nxt < lcm) {
      lcm = nxt;
      resk = k;
    }
  }
  printf("%lld", resk);
  return 0;
}
