#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  long long can = n / m;
  long long nw = (can + 1) * m - n;
  long long ans1 = nw * a;
  nw = n - can * m;
  long long ans2 = nw * b;
  long long ans = min(ans1, ans2);
  cout << ans << endl;
  return 0;
}
