#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1e9 + 7;
pair<int64_t, int64_t> countOddAndEven(vector<int64_t>& a) {
  int64_t even = 0;
  int64_t odd = 0;
  for (int64_t i = 0; i < a.size(); ++i) {
    even += a[i] % 2 == 0;
  }
  return {even, a.size() - even};
}
int64_t minAns = 1e18;
int64_t kAns = 0;
int64_t a, b;
int64_t gcd(int64_t a, int64_t b) { return b == 0 ? a : gcd(b, a % b); }
void update(int64_t k) {
  int64_t gc = gcd(a + k, b + k);
  if (((a + k) / gc) * (b + k) < minAns) {
    minAns = ((a + k) / gc) * (b + k);
    kAns = k;
  }
}
void validate(int64_t substract, int64_t i) {
  if (substract % i == 0) {
    {
      int64_t toDivideI = i - (a % i);
      update(toDivideI);
    }
    if (substract / i != i) {
      int64_t newI = substract / i;
      int64_t toDivideI = newI - (a % newI);
      update(toDivideI);
    }
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  cin >> a >> b;
  minAns = a * b / gcd(a, b);
  if (a == b) {
    cout << 0;
    return 0;
  }
  if (a > b) {
    swap(a, b);
  }
  int64_t substract = b - a;
  for (int64_t i = 2; i <= sqrt(substract + 0.5); ++i) {
    validate(substract, i);
  }
  validate(substract, substract);
  cerr << minAns << endl;
  cout << kAns << endl;
  return 0;
}
