a,b,c,d = map(int,input().split()) res = 0 for i in range(a + 1): meat = i * c if meat > b: continue if meat + i <= d: res = max(res, i) print(res)