#include <bits/stdc++.h>
using namespace std;
const int MX = 15;
const int MOD = 1000000007;
int main() {
  ios_base::sync_with_stdio(0);
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  long long cl = m * ((n - 1) / m + 1);
  long long costcl = (cl - n) * a;
  long long fl = m * (n / m);
  long long costfl = (n - fl) * b;
  cout << min(costcl, costfl) << endl;
  return 0;
}
