#include <bits/stdc++.h>
using namespace std;
long long N, M, a, b;
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> M >> a >> b;
  long long temp = N % M;
  cout << min(a * (M - temp), b * temp);
  return 0;
}
