#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int a, b;
long long int ans = LLONG_MAX;
long long int mink = LLONG_MAX;
void findmink(long long int d, long long int gap, long long int a) {
  if (a % d == 0) {
    if ((a * b) / gcd(a, gap) < ans) {
      ans = ((a * b) / gcd(a, gap));
      mink = 0;
    } else if ((a * b) / gcd(a, gap) == ans) {
      mink = min(mink, 0LL);
    }
    return;
  }
  long long int k = (((a / d) + 1) * d - a);
  if (((a + k) * (b + k)) / gcd(a + k, gap) < ans) {
    ans = ((a + k) * (b + k)) / gcd(a + k, gap);
    mink = k;
  } else if (((a + k) * (b + k)) / gcd(a + k, gap) == ans) {
    ans = ((a + k) * (b + k)) / gcd(a + k, gap);
    mink = min(mink, k);
  }
  return;
}
void send(long long int a) {
  cout << a << endl;
  exit(0);
}
int main() {
  ios_base::sync_with_stdio(0);
  ;
  cin >> a >> b;
  long long int t1 = min(a, b);
  long long int t2 = max(a, b);
  a = t1;
  b = t2;
  long long int gap = b - a;
  if (gap == 0) send(0);
  if (b % a == 0) send(0);
  if (a % gap == 0) send(0);
  for (long long int i = 1; i * i <= gap; i++) {
    if (gap % i == 0) {
      findmink(i, gap, a);
      findmink(gap / i, gap, a);
    }
  }
  send(mink);
  return 0;
}
