#include <bits/stdc++.h>
using namespace std;
long long ans1 = 0x3f3f3f3f3f3f3f3f, ans2 = 0;
long long q[101000];
int main() {
  long long a, b;
  cin >> a >> b;
  if (b < a) swap(b, a);
  long long q1 = b - a;
  long long gcd = 0, num = 0;
  for (long long i = 1; i * i <= q1; i++) {
    if (q1 % i == 0) {
      gcd = (a + i - 1) / i * i - a;
      num = (b + gcd) / i * (a + gcd);
      if (num < ans1) {
        ans1 = num;
        ans2 = gcd;
      }
      long long x = q1 / i;
      gcd = (a + x - 1) / x * x - a;
      num = (b + gcd) / x * (a + gcd);
      if (num < ans1) {
        ans1 = num;
        ans2 = gcd;
      }
    }
  }
  cout << ans2 << endl;
}
