#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, a, b, s1, s2;
  cin >> n >> m >> a >> b;
  if (n % m == 0)
    cout << "0" << endl;
  else {
    s1 = (n - ((n / m) * m)) * b;
    s2 = (((n / m) + 1) * m - n) * a;
    if (s1 > s2)
      printf("%I64d", s2);
    else
      printf("%I64d", s1);
  }
  return 0;
}
