#include <bits/stdc++.h>
using namespace std;
long long a, b, delta, min_lcm, min_k;
vector<pair<long long, int> > factors;
void get_factors(long long x) {
  for (long long i = 2; i * i <= x; ++i)
    if (x % i == 0) {
      int pow = 0;
      while (x % i == 0) {
        pow++;
        x /= i;
      }
      factors.emplace_back(i, pow);
    }
  if (x > 1) factors.emplace_back(x, 1);
}
inline long long gcd(long long x, long long y) {
  if (x < y) swap(x, y);
  while (y) {
    x = x % y;
    swap(x, y);
  }
  return x;
}
inline long long lcm(long long x, long long y) { return x * y / gcd(x, y); }
void dfs(int p, long long n) {
  if (p >= factors.size()) {
    long long k;
    if (a % n == 0)
      k = 0;
    else
      k = n - a % n;
    long long t_lcm = lcm(a + k, b + k);
    if (t_lcm < min_lcm) {
      min_lcm = t_lcm;
      min_k = k;
    }
    if (t_lcm == min_lcm && k < min_k) min_k = k;
    return;
  }
  dfs(p + 1, n);
  for (int i = 1; i <= factors[p].second; ++i) {
    n *= factors[p].first;
    dfs(p + 1, n);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> a >> b;
  delta = abs(a - b);
  if (delta <= 1) {
    cout << 0;
    return 0;
  }
  get_factors(delta);
  min_lcm = lcm(a, b);
  min_k = 0;
  dfs(0, 1);
  cout << min_k;
}
