#include <bits/stdc++.h>
using namespace std;
long long a, b, ans, ansk, k = 0, cnt;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    gcd(b, a % b);
}
long long solve(long long x) {
  long long t = a / x;
  if (a % x) t++;
  k = x * t - a;
  long long bns = (b + k) * (a + k) / gcd(a + k, b + k);
  return bns;
}
int main() {
  cin >> a >> b;
  if (a == b) {
    cout << 0 << endl;
    return 0;
  }
  if (a > b) {
    long long t = a;
    a = b;
    b = t;
  }
  cnt = b - a;
  ans = -1;
  for (long long i = 1; i * i <= cnt; i++) {
    if (cnt % i == 0) {
      long long zz = solve(i);
      if (ans > zz || ans == -1) {
        ans = zz;
        ansk = k;
      } else if (ans == zz && ansk > k)
        ansk = k;
      zz = solve(cnt / i);
      if (ans > zz || ans == -1) {
        ans = zz;
        ansk = k;
      } else if (ans == zz && ansk > k)
        ansk = k;
    }
  }
  cout << ansk << endl;
  return 0;
}
