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