#include <iostream>
#include <algorithm>
using namespace std;
int x, y, w, h;
int tmp1, tmp2, ans;
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin >> x >> y >> w >> h;
tmp1 = min(x, y);
tmp2 = min(w-x, h-y);
ans = min(tmp1, tmp2);
cout << ans;
return 0;
}