#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
long long int n, i, j, k, m, a, b, ans = 0;
int main() {
  vector<pair<int, int>> v;
  cin >> n >> m >> a >> b;
  if (n < m) {
    if (b * n < (m - n) * a)
      cout << b * n;
    else
      cout << (m - n) * a;
    return 0;
  }
  if ((n % m) == 0)
    cout << "0";
  else {
    j = (n / m);
    if ((m * (j + 1) - n) * a < (n - m * j) * b)
      cout << (m * (j + 1) - n) * a;
    else
      cout << (n - m * j) * b;
  }
  for (i = 0; i < n; i++) {
  }
  return 0;
}
