#include <bits/stdc++.h>
using namespace std;
bool c1[100001], c2[100001], c3[100001], c4[100001];
int main() {
int a, b, c, d;
queue<vector<int> > q;
scanf("%d %d %d %d", &a, &b, &c, &d);
q.push({ 0, 0, 0 });
c1[0] = true;
c3[0] = true;
while (!q.empty()) {
vector<int> now = q.front();
q.pop();
if (now[0] == c && now[1] == d) {
printf("%d", now[2]);
return 0;
}
if (c2[now[1]] == false) {
c2[now[1]] = true;
q.push({ a, now[1], now[2] + 1 });
}
if (c4[now[0]] == false) {
c4[now[0]] = true;
q.push({ now[0], b, now[2] + 1 });
}
if (c1[now[1]] == false) {
c1[now[1]] = true;
q.push({ 0, now[1], now[2] + 1 });
}
if (c3[now[0]] == false) {
c3[now[0]] = true;
q.push({ now[0], 0, now[2] + 1 });
}
if (now[0] > b - now[1] && c4[now[0] - b + now[1]] == false) {
c4[now[0] - b + now[1]] = true;
q.push({ now[0] - b + now[1], b, now[2] + 1 });
}
if (now[0] <= b - now[1] && c1[now[1] + now[0]] == false) {
c1[now[1] + now[0]] = true;
q.push({ 0, now[1] + now[0], now[2] + 1 });
}
if (now[1] > a - now[0] && c2[now[1] - a + now[0]] == false) {
c2[now[1] - a + now[0]] = true;
q.push({ a, now[1] - a + now[0], now[2] + 1 });
}
if (now[1] <= a - now[0] && c3[now[0] + now[1]] == false) {
c3[now[0] + now[1]] = true;
q.push({ now[0] + now[1], 0, now[2] + 1 });
}
}
printf("-1");
return 0;
}