#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, a, b, res = LLONG_MAX;
  cin >> n >> m >> a >> b;
  res = min(res, (n - (n / m * m)) * b);
  res = min(res, ((n / m + 1) * m - n) * a);
  cout << res;
  return 0;
}
