#include <bits/stdc++.h>
using namespace std;
int main() {
  {
    long long int a, b, c = 0, d, e, i, j, k, l, m, p, n, q, r, t, u, val, w,
                        tc, mn = 2134567891, mx = 0, sum = 0, ans = 0;
    cin >> a >> b >> c >> d;
    p = a / b;
    q = a % b;
    if (p * b != a) p = b - q;
    p = p * c;
    q = q * d;
    cout << min(p, q);
  }
  return 0;
}
