#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC target("avx")
const long long INF = numeric_limits<long long>::max() / 2;
const long double PI = 3.1415926535898;
const long long MOD = 1e9 + 7;
const long long LIM = 2e6 + 5;
long long fpow(long long x, long long y) {
  long long temp;
  if (y == 0) return 1;
  temp = fpow(x, y / 2);
  if (y % 2 == 0)
    return (temp * temp) % MOD;
  else
    return (x * ((temp * temp) % MOD)) % MOD;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void aurkrosolve(long long q, long long a, long long b, long long& ansk,
                 long long& ansgcd) {
  long long ele = ceil(1.0 * a / q);
  long long k = q * ele - a;
  long long jeecd = ((a + k) * (b + k)) / gcd(a + k, b + k);
  if (jeecd < ansgcd) {
    ansgcd = jeecd;
    ansk = k;
  } else if (jeecd == ansgcd && k < ansk)
    ansk = k;
}
void solve() {
  long long a, b;
  cin >> a >> b;
  if (a > b) swap(a, b);
  long long ansgcd = (a * b) / gcd(a, b), ansk = 0, diff = b - a;
  for (long long i = 1; i * i <= diff; ++i) {
    if (diff % i == 0) {
      long long ele1 = i, ele2 = diff / i;
      aurkrosolve(ele1, a, b, ansk, ansgcd);
      aurkrosolve(ele2, a, b, ansk, ansgcd);
    }
  }
  cout << ansk << "\n";
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  { solve(); }
  return 0;
}
