#include using namespace std; int main(){ int a, b, c, d,tmp; cin >> a >> b >> c >> d; while(true){ tmp = b / c; if(tmp + tmp * c < d) break; b -= c; } if(a < tmp) cout << a << "\n"; else cout << tmp << "\n"; return 0; }