#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long sum = 0, ff = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (isdigit(ch)) sum = sum * 10 + (ch ^ 48), ch = getchar();
  return sum * ff;
}
signed main() {
  long long n, m, a, b;
  n = read();
  m = read();
  if (n % m == 0) return puts("0"), 0;
  a = read();
  b = read();
  long long up = (n / m + 1) * m;
  long long down = (n / m) * m;
  down = max(down, 0ll);
  printf("%lld\n", min(a * (up - n), b * (n - down)));
}
