#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1000000007;
int64_t power(int64_t a, int64_t b, int64_t p) {
  int64_t ans = 1;
  while (b) {
    if (b & 1) {
      ans = (ans * a) % p;
    }
    a = (a * a) % p;
    b >>= 1;
  }
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int64_t a, b;
  cin >> a >> b;
  if (a > b) swap(a, b);
  int64_t d = b - a;
  vector<int64_t> di;
  for (int64_t i = 1; i * i <= d; i++) {
    if (d % i == 0) di.push_back(d / i), di.push_back(i);
  }
  int64_t an = 0;
  int64_t cur = 4e18;
  for (auto& j : di) {
    int64_t k = a % j;
    k = (j - k) % j;
    int64_t l = (a + k) * (b + k) / j;
    if (l < cur)
      an = k, cur = l;
    else if (l == cur)
      an = min(an, k);
  }
  cout << an << endl;
  return 0;
}
