#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const int mod = 1e9 + 7;
vector<pair<int, int> > dev;
long long ans = 2e18 + 10, ans1 = 1e18;
long long a, b;
void dfs(long long x, int n) {
  if (n == dev.size()) {
    long long k;
    if (a % x == 0) {
      k = 0;
    } else {
      k = a / x * x + x - a;
    }
    if ((a + k) / x * (b + k) < ans) {
      ans1 = k;
      ans = (a + k) / x * (b + k);
    } else if ((a + k) / x * (b + k) == ans) {
      ans1 = min(k, ans1);
    }
    return;
  }
  for (int i = 0; i <= dev[n].second; i++) {
    dfs(x, n + 1);
    x *= dev[n].first;
  }
}
int main() {
  cin >> a >> b;
  if (a > b) swap(a, b);
  long long n = b - a;
  if (n == 0) {
    cout << 0;
    return 0;
  }
  long long up = sqrt(n);
  for (int i = 2; i <= up; i++) {
    int t = 0;
    while (n % i == 0) {
      t++;
      n /= i;
    }
    if (t) {
      dev.push_back(make_pair(i, t));
    }
  }
  dev.push_back(make_pair(n, 1));
  dfs(1, 0);
  cout << ans1;
}
