#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const long long int N = 100005;
long long int givesm(long long int b, long long int cnt) {
  long long int n, ans;
  n = b / cnt + bool(b % cnt);
  ans = n * cnt;
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  {
    long long int i, j, k, n, m, ans = 0, cnt = 0, sum = 0, fans;
    long long int a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    cnt = b - a;
    if (!cnt) {
      cout << 0;
      return 0;
    }
    ans = givesm(b, b - a);
    sum = (ans * (ans - cnt)) / cnt;
    fans = ans - b;
    for (i = 1; i * i <= cnt; i++) {
      if (cnt % i == 0) {
        long long int temp1 = i;
        ans = givesm(b, temp1);
        long long int temp2 = (ans * (ans - cnt)) / temp1;
        if (temp2 < sum) {
          fans = ans - b;
          sum = temp2;
        } else if (temp2 == sum) {
          fans = min(fans, ans - b);
        }
        temp1 = cnt / i;
        ans = givesm(b, temp1);
        temp2 = (ans * (ans - cnt)) / temp1;
        if (temp2 < sum) {
          fans = ans - b;
          sum = temp2;
        } else if (temp2 == sum) {
          fans = min(fans, ans - b);
        }
      }
    }
    cout << fans;
  }
}
