#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int maxn = 1e5;
const int INF = 0x7fffffff;
const int mod = 1e9 + 7;
const double eps = 1e-7;
const double Pi = acos(-1.0);
inline int read_int() {
  char c;
  int ret = 0, sgn = 1;
  do {
    c = getchar();
  } while ((c < '0' || c > '9') && c != '-');
  if (c == '-')
    sgn = -1;
  else
    ret = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  return sgn * ret;
}
inline long long read_ll() {
  char c;
  long long ret = 0, sgn = 1;
  do {
    c = getchar();
  } while ((c < '0' || c > '9') && c != '-');
  if (c == '-')
    sgn = -1;
  else
    ret = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  return sgn * ret;
}
vector<long long> v;
long long a, b;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
  cin >> a >> b;
  if (a > b) swap(a, b);
  if (a == b) {
    cout << 0 << endl;
    return 0;
  }
  long long n = b - a;
  for (long long i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      v.push_back(i);
      v.push_back(n / i);
    }
  }
  long long ans = a / gcd(a, b) * b, res = 0;
  for (int i = 0; i < v.size(); ++i) {
    long long x = (v[i] - a % v[i]);
    long long y = gcd(a + x, b + x);
    if (((x + a) / y) * (b + x) < ans) {
      ans = ((x + a) / y) * (b + x);
      res = x;
    } else if (((x + a) / y) * (b + x) == ans && x < res)
      res = x;
  }
  cout << res << endl;
  return 0;
}
