var n, m, x, y: Longint;
             t: Longint;

begin
 readln(n, m, x, y);
 if  n > m
  then begin
        t := n;
        n := m;
        m := t;
       end;

 if m - y < y
  then y := m - y;
 if n - x < x
  then x := n - x;

 if y < x
  then writeln(y)
  else writeln(x)
end.
