import sys from typing import Counter readline=sys.stdin.readline write=sys.stdout.write A,B,N,M=map(int,readline().split()) ans=min(A,B) A-=ans B-=ans ans+=max(A//(N+1),B//(M+1)) print(ans)