a,b,c,d = map(int,input().split()) val_m = 0 for i in range(0,101): yasai = i niku = i*c if yasai<=a and niku<=b and yasai+niku<=d: if val_m < yasai: val_m=yasai print(val_m)