#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
vector<ll> divi;
void Find(ll n) {
  ll si = sqrtl(n);
  for (ll i = 1; i <= si; i++) {
    if (n % i == 0) {
      if (n / i == i) {
        divi.push_back(i);
      } else {
        divi.push_back(n / i);
        divi.push_back(i);
      }
    }
  }
  sort(divi.begin(), divi.end());
}
int main() {
  ll a, b, i, j;
  cin >> a >> b;
  if (a < b) swap(a, b);
  if (a == b) {
    cout << 0 << endl;
    return 0;
  }
  ll num = a - b;
  ll have = b;
  if (have < num) {
    ll x_divides = have - num;
    Find(num);
    ll indx = 0;
    for (ll v : divi) {
      if (v >= have) {
        indx = v;
        break;
      }
    }
    cout << indx - b << endl;
    return 0;
  }
  ll term = have / num;
  if (have % num) term++;
  ll make = term * num;
  cout << make - have << endl;
  return 0;
}
