#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  if (n % m == 0) {
    cout << 0;
  } else {
    long long val = n / m;
    long long one = (n - m * val) * b;
    long long two = (m * (val + 1) - n) * a;
    cout << min(one, two);
  }
  return 0;
}
