#include <bits/stdc++.h>
using namespace std;
const int maxn = 25;
const int maxm = maxn * 2;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
long long a, b;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie(0);
  cin >> a >> b;
  if (a > b)
    swap(a, b);
  else if (a == b) {
    cout << 0 << endl;
    return 0;
  }
  vector<long long> v;
  for (long long i = 1; i * i <= (b - a); i++) {
    if ((b - a) % i == 0) {
      v.push_back(i);
      if (i * i != (b - a)) v.push_back((b - a) / i);
    }
  }
  long long ans = 8e18;
  long long k = 0;
  for (int i = 0; i < v.size(); i++) {
    long long t = 0;
    if (a % v[i] != 0) {
      t = v[i] - a % v[i];
    }
    long long tmp = lcm(a + t, b + t);
    if (tmp < ans) {
      ans = tmp;
      k = t;
    }
  }
  cout << k << endl;
  return 0;
}
