#include <bits/stdc++.h>
using namespace std;
int INF = 2000000000;
int main(int argv, char** args) {
  ios_base::sync_with_stdio(0);
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  long long down = n / m * m;
  long long up = down + m;
  cout << min((n - down) * b, (up - n) * a) << endl;
  return 0;
}
