#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
double PI = 4 * atan(1);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  if (n % m == 0) {
    cout << 0;
  } else {
    cout << min(b * (n - n / m * m), a * ((n / m + 1) * m - n));
  }
}
