#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, d, ans = 100000000000000, k, kk = 0;
  cin >> a >> b;
  d = abs(b - a);
  for (long long i = 1; i <= sqrt(d); i += 1) {
    if (d % i == 0) {
      k = (i - a % i) % i;
      long long t = (a + k) / i * (b + k);
      if (t < ans) {
        ans = t;
        kk = k;
      }
      long long ii = d / i;
      k = (ii - a % ii) % ii;
      t = (a + k) / ii * (b + k);
      if (t < ans) {
        ans = t;
        kk = k;
      }
    }
  }
  cout << kk;
}
