#include <bits/stdc++.h>
using namespace std;
long long n, m, k, tempk;
long long a, b, c, A;
string s;
long long gcd(long long a, long long b) {
  while (a % b != 0) {
    a = a % b;
    swap(a, b);
  }
  return b;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> a >> b;
  if (a < b) swap(a, b);
  long long r = a - b;
  long long minv = a * b / gcd(a, b);
  for (long long i = 1; i * i <= r; i++) {
    if (r % i == 0) {
      n = i;
      tempk = (n - b % n) % n;
      if (minv > (a + tempk) * (b + tempk) / n) {
        minv = (a + tempk) * (b + tempk) / n;
        k = tempk;
      }
      n = r / i;
      tempk = (n - b % n) % n;
      if (minv > (a + tempk) * (b + tempk) / n) {
        minv = (a + tempk) * (b + tempk) / n;
        k = tempk;
      }
    }
  }
  cout << k;
  return 0;
}
