#include<iostream> #include<cmath> using namespace std; int main(){ int x,y,p,q; cin>>x>>y>>p>>q; cout<<min(x-p,min(x-q,min(y-p,y-q))); return 0; }