#include <bits/stdc++.h>
using namespace std;
long gcd(long a, long b) {
  if (a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  long long lecm = a / gcd(a, b) * b;
  return lecm;
}
int main() {
  long long a, b;
  cin >> a >> b;
  long k = 0;
  if (a < b) swap(a, b);
  long long dif = a - b;
  vector<long long> v;
  for (int i = 1; i * i < dif; i++) {
    if (dif % i == 0) {
      v.push_back(i);
      if (i != dif / i) {
        v.push_back(dif / i);
      }
    }
  }
  sort(v.begin(), v.end());
  long long min = 1e18;
  int best = 0;
  int size = v.size();
  for (int i = 0; i < size; i++) {
    long long num = v[i];
    if (a % num == 0) {
      long long lecm = lcm(a, b);
      if (lecm < min) {
        min = lecm;
        best = 0;
      }
    } else {
      long long lecm = lcm(a + num - a % num, b + num - b % num);
      if (lecm < min) {
        min = lecm;
        best = num - a % num;
      }
    }
  }
  cout << best << endl;
}
