#include <bits/stdc++.h>
using namespace std;
unsigned long long cream_time(unsigned long long in1, unsigned long long int2,
                              unsigned long long time);
int main() {
  unsigned long long a = 0, b = 0, c = 0, d = 0;
  unsigned long long catched_time = 0, cream_count = 0;
  unsigned long long Rick_time = 0;
  bool Is_catched = false;
  cin >> a >> b;
  cin >> c >> d;
  for (unsigned long long i = cream_count; i < c + cream_count; i++) {
    Rick_time = cream_time(a, b, i);
    if (Rick_time < d) {
      cream_count++;
    } else {
      if ((Rick_time - d) % c == 0) {
        Is_catched = true;
        catched_time = Rick_time;
        break;
      }
    }
  }
  if (true == Is_catched) {
    cout << catched_time << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
unsigned long long cream_time(unsigned long long in1, unsigned long long in2,
                              unsigned long long time) {
  unsigned long long result = 0;
  result = in2 + time * in1;
  return result;
}
