#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long n, m;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  long long x = abs(n - m);
  long long mr = n * m / gcd(n, m), mi = 0;
  for (long long i = 1; i * i <= x; ++i) {
    if (x % i != 0) continue;
    long long a = i, b = x / i;
    long long w1 = a - n % a, w2 = b - n % b;
    long long res1 = (n + w1) * (m + w1) / gcd((n + w1), (m + w1));
    long long res2 = (n + w2) * (m + w2) / gcd((n + w2), (m + w2));
    if (res1 < mr) mr = res1, mi = w1;
    if (res1 <= mr && w1 < mi) mr = res1, mi = w1;
    if (res2 < mr) mr = res2, mi = w2;
    if (res2 <= mr && w2 < mi) mr = res2, mi = w2;
  }
  cout << mi << '\n';
}
