#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
long long n, m, a, b, x, y, mx = 1e9;
bool compare(string a, string b) { return a.length() < b.length(); }
bool check = false;
int main() {
  cin >> n >> m >> a >> b;
  if (n % m == 0) {
    printf("0");
    return 0;
  }
  long long o = (n + m - 1) / m;
  x = ((o * m) - n) * a;
  y = b * (n % m);
  cout << min(x, y);
}
