#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define i128 _int128
#define fi first
#define se second
#define pb push_back
#define endl '\n'
//#define int long long
const ll INF=0x3f3f3f3f;
const ll N=1e2+9;
const int mod=1e4;
inline int read(){
int ans=0,sign=1;
char ch = getchar();
while(ch<'0'||ch>'9'){
if(ch=='-'){
sign=-1;
}
ch=getchar();
}
while(ch>='0'&&ch<='9'){
ans = ans*10 + ch-'0';
ch = getchar();
}
return ans*sign;
}
const int N = 1e2 + 10;
const int mod = 998244353;
int dp[N][N][2];
int x,y,p,q;
void bfs() {
queue<pair<pair<int,int>,int>>c;
c.push({{x,y},0});
dp[x][y][0]=0;
while (!c.empty()) {
int nowx=c.front().first.first;
int nowy=c.front().first.second;
int flag=c.front().second;
c.pop();
for (int i=nowx; i>=0; i--) {
for (int j=nowy; j>=0; j--) {
if ((i+j<=p)&&(nowx-i+q>=nowy-j||nowx-i==0)) {
if (dp[x-nowx+i][y-nowy+j][flag^1]>dp[nowx][nowy][flag]+1) {
dp[x-nowx+i][y-nowy+j][flag^1]=dp[nowx][nowy][flag]+1;
c.push({{x-nowx+i,y-nowy+j},flag^1});
}
}
}
}
}
}
void solved() {
cin>>x>>y>>p>>q;
for (int i=0; i<=100; i++) {
for (int j=0; j<=100; j++) {
for (int k=0; k<=1; k++) {
dp[i][j][k]=1e18;
}
}
}
bfs();
int minn=1e18;
for (int i=0; i<=y; i++) {
minn=min(dp[x][i][1],minn);
}
if (minn>=1e18) {
cout<<"-1\n";
} else {
cout<<minn<<"\n";
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
// cin>>t;
while (t--) {
solved();
}
}