def main(): A, B, C, D = map(int, input().split(" ")) for i in range(A + 1): if i + C*i > D or C*i > B: print(i - 1) break if __name__ == "__main__": main()