#include<bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define All(x) (x).begin(),(x).end()
#define mp make_pair
#define nl "\n"
typedef pair<int,int>ii;
typedef vector<int>vi;
typedef vector<ii>vii;
typedef vector<vi>vvi;
typedef vector<long long>vl;
typedef vector <vl>vvl;
template<class T>
void print(T& a)
{
    for(auto x:a)
        cout<<x<<" ";
    cout<<"\n";
}
int main()
{

    FastIO

    int a[3];
    for(int &x:a)cin>>x;
    sort(a,a+3);

    cout<<a[1]+a[2]<<nl;

    return 0;
}
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//const int MOD =  998244353;
 
const ll INF = 1LL<<60;
const int IINF = 1000000000;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll X, Y, A, B; cin >> X >> Y >> A >> B;
    Y--;
    ll ans = 0;
    rep(i,100){
        ll str = X;
        ll i_count = 0;
        rep(j,i){
            if ((Y+(A-1)) / A <= str){
                i_count = j;
                break;
            } 
            str *= A;
            i_count = j+1;
            
        }
        //cout << i_count << endl;
        if(Y <= str) continue;
        ll remain = Y - str;
        
        ll count = remain/B;
        
        /*cout << i << endl;
        cout << str << endl;
        cout << count << endl;
        */
        ans = max(ans, (ll)(count+i_count));

        
    }

    cout << ans << endl;

}
