#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
long long a, b;
long long ans;
long long v;
void test2(long long div) {
  long long A = (a + div - 1) / div;
  long long k = A * div - a;
  long long cv = (a + k) / div * (b + k);
  if (cv < v) {
    ans = k;
    v = cv;
  } else if (cv == v) {
    ans = min(ans, k);
  }
}
void test(long long x) {
  for (long long div = 1; div * div <= x; ++div) {
    if (x % div == 0) {
      test2(div);
      test2(x / div);
    }
  }
}
int main() {
  scanf("%lld%lld", &a, &b);
  if (a == b) {
    printf("0\n");
    return 0;
  }
  if (a > b) {
    swap(a, b);
  }
  long long diff = b - a;
  long long A = (a + diff - 1) / diff;
  long long k = A * diff - a;
  ans = k;
  v = (a + k) / diff * (b + k);
  test(diff);
  printf("%lld\n", ans);
}
