#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, k, ans = 0, mn = 99999999999999999, div, r, dif;
  cin >> a >> b;
  if (a == b) {
    cout << 0;
    return 0;
  }
  if (a > b) swap(a, b);
  dif = b - a;
  for (int d = 1; d * d <= dif; d++)
    if (dif % d == 0) {
      div = d;
      r = a % div;
      k = (div - r) % div;
      if ((a + k) * (b + k) / div < mn) {
        mn = (a + k) * (b + k) / div;
        ans = k;
      }
      if (d * d != dif) {
        div = dif / d;
        r = a % div;
        k = (div - r) % div;
        if ((a + k) * (b + k) / div < mn) {
          mn = (a + k) * (b + k) / div;
          ans = k;
        }
      }
    }
  cout << ans;
  return 0;
}
