#include <bits/stdc++.h>
using namespace std;
template <typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) {
  return os << pai.first << ' ' << pai.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
  for (int i = 0, _i = (((int)(v).size())); i < _i; i++) cout << v[i] << ' ';
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> s) {
  for (T p : s) cout << p << ' ';
  return os;
}
template <typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> s) {
  for (auto p : s) cout << '(' << p << ") ";
  return os;
}
template <typename T, typename V>
istream &operator>>(istream &is, pair<T, V> &pai) {
  is >> pai.first >> pai.second;
  return is;
}
long long a, b;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  if (a > b) return gcd(b, a);
  return gcd(b % a, a);
}
pair<long long, long long> test(int v) {
  ;
  long long k = v - a % v;
  if (k == v) k = 0;
  ;
  return make_pair((a + k) / gcd(a + k, b + k) * (b + k), k);
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cin >> a >> b;
  if (a < b) swap(a, b);
  if (a == b) {
    cout << 0 << '\n';
    return 0;
  }
  pair<long long, long long> res = make_pair(a * b / gcd(a, b), 0);
  for (long long i = 1; i * i <= a - b; i++) {
    if ((a - b) % i == 0) {
      res = min(res, test(i));
      res = min(res, test((a - b) / i));
    }
  };
  cout << res.second << '\n';
}
