#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int MAX = 2e5 + 10;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  int a, b, kk = 0;
  long long minn = 1e18 + 1;
  cin >> a >> b;
  if (a > b) swap(a, b);
  if (a % b == 0 || b % a == 0) {
    cout << 0;
    return 0;
  }
  long long d = b - a;
  for (int i = 1; i * i <= d; i++) {
    if (d % i == 0) {
      long long k = 0;
      long long ii = i, ii2 = d / i;
      if (b % ii != 0)
        k = (b / ii + 1) * ii - b;
      else
        k = 0;
      if ((a + k) * (b + k) / ii < minn) {
        minn = (a + k) * (b + k) / i;
        kk = k;
      }
      if (b % ii2 != 0)
        k = (b / ii2 + 1) * ii2 - b;
      else
        k = 0;
      if ((a + k) * (b + k) / ii2 < minn) {
        minn = (a + k) * (b + k) / ii2;
        kk = k;
      }
    }
  }
  cout << kk;
}
