#include <bits/stdc++.h>          
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;

ll N;
ll A[3030][5];
ll cnt[1<<5];

ll getmsk(ll i, ll x) {
    ll res = 0;
    rep(j,5) if (x<=A[i][j]) res |= (1<<j);
    return res;
}

bool OK(ll x) {
    rep(i,1<<5) cnt[i] = 0;
    rep(i,N) cnt[getmsk(i,x)]++;
    rep(i,1<<5) rep(j,1<<5) rep(k,1<<5) {
        ll bit = i | j | k;
        if (bit!=(1<<5)-1) continue;
        if (cnt[i]==0 || cnt[j]==0 || cnt[k]==0) continue;
        return true;
    }
    return false;
}

int main() {
    cin >> N;
    rep(i,N) rep(j,5) cin >> A[i][j];

    ll l = 0, r = 1e9+1;
    while (r-l>1) {
        ll m = (l+r)/2;
        bool flag = OK(m);
        if (flag) l = m;
        else r = m;
    }

    cout << l << endl;
}
#include <bits/stdc++.h>
using namespace std;

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


int main(){
    LL X, Y, A, B, ans = 0;
    cin >> X >> Y >> A >> B;

    while (X < LONG_MAX / A && X * A < X + B && X * A < Y) {
        X *= A;
        ans++;
    }

    cout << (ans + (Y - X - 1) / B) << endl;
}
