#include <bits/stdc++.h>
using namespace std;
const long long MAXN = (long long)((1e5) + 10);
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long max(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
long long min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
long long cbrt(long long x) {
  long long lo = 1, hi = min(2000000ll, x);
  while (hi - lo > 1) {
    long long mid = (lo + hi) / 2;
    if (mid * mid * mid < x) {
      lo = mid;
    } else
      hi = mid;
  }
  if (hi * hi * hi <= x)
    return hi;
  else
    return lo;
}
const long long dx[4] = {-1, 1, 0, 0};
const long long dy[4] = {0, 0, -1, 1};
const long long N = 5 * 1e6 + 4;
bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }
long long countbits(long long num) {
  long long c = 0;
  while (num) {
    if (!(num & 1)) c++;
    num >>= 1;
  }
  return c;
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  srand(time(NULL));
  long long t = 1;
  while (t--) {
    long long a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    long long dif = b - a;
    if (dif == 1) {
      cout << 0;
      return 0;
    }
    long long num = (a * b) / gcd(a, b);
    if (num == b) {
      cout << 0;
      return 0;
    }
    long long mini = 0;
    long long minimum = num;
    for (long long i = 1; i * i <= dif; i++) {
      if (dif % i == 0) {
        long long x = (i - (a % i));
        if (a % i == 0) x = 0;
        long long g = (a + x) * (b + x) / gcd(a + x, b + x);
        if (g < minimum) {
          minimum = g;
          mini = x;
        } else if (g == minimum && x < mini)
          mini = x;
        long long sec = dif / i;
        if (sec != i) {
          x = (sec - (a % sec));
          if (a % sec == 0) x = 0;
          g = ((a + x) * (b + x)) / gcd(a + x, b + x);
          if (g < minimum) {
            minimum = g;
            mini = x;
          } else if (g == minimum && x < mini)
            mini = x;
        }
      }
    }
    cout << mini;
  }
  return 0;
}
