#include <bits/stdc++.h>
using namespace std;
long a, b, k;
void solve() {
  if (a < b - a) {
    long deduction = b - a;
    for (long i = 1; i <= sqrt(deduction); i++) {
      if (deduction % i == 0)
        if (i >= a) {
          k = i - a;
          return;
        }
    }
    for (long i = sqrt(deduction); i >= 1; i--) {
      if (deduction % i == 0) {
        long left = deduction / i;
        if (left >= a) {
          k = left - a;
          return;
        }
      }
    }
  } else if (b == a) {
    k = 0;
  } else {
    long deduction = b - a;
    long left = a / deduction;
    if (left * deduction < a) left += 1;
    k = left * deduction - a;
  }
}
void read() {
  cin >> a >> b;
  if (a > b) {
    long tg = b;
    b = a;
    a = tg;
  }
  solve();
  cout << k << "\n";
}
int main(int argc, const char* argv[]) {
  read();
  return 0;
}
