#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, a, b, mo;
  scanf("%lld", &n), scanf("%lld", &m), scanf("%lld", &a), scanf("%lld", &b);
  if (n % m == 0) {
    printf("0\n");
    return 0;
  }
  long long t1, t2;
  mo = n % m;
  t1 = ceil(n / (double)m);
  t1 = t1 * m - n;
  t1 = t1 * a;
  t2 = mo * b;
  t1 = min(t1, t2);
  printf("%lld\n", t1);
}
