#include <bits/stdc++.h>
using namespace std;
long long inf = 2147483647;
const long long ll = 9223372036854775807, ninf = 1000000000;
const double eps = 1e-6;
const long long nll = 1000000000000000000;
long long res = ll;
long long ans = 0;
long long a, b;
long long solve(long long x) {
  long long t = (b + x - 1) / x * x - b;
  long long now = (a + t) * (b + t) / x;
  if (now < res) {
    res = now;
    ans = t;
  }
}
int main() {
  while (cin >> a >> b) {
    if (a > b) {
      swap(a, b);
    }
    for (long long i = 1; i * i <= (b - a); i++) {
      if ((b - a) % i == 0) {
        solve(i);
        solve((b - a) / i);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
