#include <bits/stdc++.h>
using namespace std;
vector<long long int> v;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  long long int a, b, c, d, k, val, val1, val2, ans, i, j;
  cin >> a >> b;
  c = min(a, b);
  d = max(a, b);
  a = c;
  b = d;
  c = b - a;
  val = (a * b) / gcd(a, b);
  ans = 0;
  for (i = 1; i <= sqrt(c); i++) {
    if (c % i == 0) {
      v.push_back(i);
      if (c / i != i) v.push_back(c / i);
    }
  }
  for (i = 0; i < v.size(); i++) {
    if (a % v[i] == 0) {
      val1 = (a * b) / v[i];
      if (val1 <= val) {
        val = val1;
        ans = 0;
      }
    } else {
      val2 = a % v[i];
      val2 = v[i] - val2;
      val1 = ((a + val2) * (b + val2)) / v[i];
      if (val1 < val) {
        val = val1;
        ans = val2;
      } else if (val1 == val) {
        ans = min(ans, val2);
      }
    }
  }
  cout << ans;
  return 0;
}
