#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
  ll n, m, a, b;
  cin >> n >> m >> a >> b;
  if (!(n % m)) {
    cout << 0 << endl;
    return;
  }
  ll next = (n / m + 1) * m;
  ll rem = n % m;
  ll build = (next - n) * a;
  ll destroy = rem * b;
  cout << min(build, destroy);
}
int main() { solve(); }
