#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  unsigned long long n, m;
  int a, b;
  cin >> n >> m >> a >> b;
  long long p1 = ((n + m - 1) / m * m - n) * a;
  long long p2 = (n - (n / m * m)) * b;
  cout << min(p1, p2) << endl;
  return 0;
}
