#include <bits/stdc++.h>

using namespace std;

typedef long long ll; 

int main(){
	ll x,y,a,b;
	cin >> x >> y >> a >> b;
	ll ans = 0;
	y--;
	for(ll i = 0; ; ++i){
		ll c = i+(y-x)/b;
		ans = max(ans,c);
		if(x <= y/a)
			x*=a;
		else
			break;
	}
	cout << ans << "\n";
	return 0;
}


#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
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;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << " " << p.second << ")";
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	rep(i, v.size()) {
		if (i) os << " ";
		os << v[i];
	}
	return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
	rep(i, v.size()) { is >> v[i]; }
	return is;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
#ifdef LOCAL
#define dbg(x) cerr << #x << ": " << (x) << '\n'
#define say(x) cerr << (x) << '\n'
#else
#define dbg(x)
#define say(x)
#endif
string solve(bool a) { return ((a) ? "Yes" : "No"); }
int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	int ans = INF;

	cin >> n;
	int cnt=INF;
	int cnt2 = INF;
	VPi data(n);
	cin >> data;
	rep(i, n) { chmin(ans, data[i].F + data[i].S); }
	sort(all(data));
	rep(i, n) {
		if (i == 0) {
			cnt = data[i].F;
		} else {
			chmin(cnt2, data[i].S);
		}
		swap(data[i].F, data[i].S);
	}
	chmin(ans, max(cnt , cnt2));
	sort(all(data));
	cnt2 = INF;

	rep(i, n) {
		if (i == 0) {
			cnt = data[i].F;
		} else {
			chmin(cnt2, data[i].S);
		}
		swap(data[i].F, data[i].S);
	}
	chmin(ans, max(cnt, cnt2));
	cout << ans << endl;
}