#include <stdio.h>

int main() {
    int x,y,w,h,i,j;
    scanf("%d %d %d %d",&x,&y, &w, &h);
    i = (w-x) < x ? (w-x) : x;
    j = (h-y) < y ? (h-y) : y;
    printf("%d\n", i<j ? i : j);

    return 0;
}