#include #define int long long using namespace std; signed main() { int A, B, C, D; cin >> A >> B >> C >> D; int ans = 0; for( int yasai = 0; yasai <= A; yasai++ ){ for( int niku = yasai*C; niku <= B; niku+=C ){ if( yasai + niku <= D ) ans = yasai; } } cout << ans << endl; }