#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define debug(a) { cerr << #a << ':' << a << endl; }
#define endl '\n'
#define fi first
#define se second
using lint = long long;
using P = pair<int,int>;
template<class T> using V = vector<T>;
template<class T> using priq     = priority_queue<T>;
template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
template<class T> T ceil(const T &a, const T &b) { return (a+b-1)/b; }
template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;

template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) {
    return in >> p.first >> p.second;
}
template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) {
    return out << p.first << ' ' << p.second;
}
template<class T> istream& operator>>(istream &in, vector<T> &v) {
    for(auto &&e: v) in >> e;
    return in;
}
template<class T> ostream& operator<<(ostream &out, const vector<T> &v) {
    for(const auto &e: v) out << e << ' ';
    return out;
}

/*----------------------------------------------------------------------------------------------------*/

bool f(int x, V<V<int>> &as) {
    set<V<bool>> st;
    int n = sz(as);
    rep(i,n) {
        V<bool> v(5);
        rep(j,5) v[j] = (as[i][j] >= x);
        st.insert(v);
    }

    bool res = false;
    for(auto i: st) for(auto j: st) for(auto k: st) {
        bool ok = true;
        rep(l,5) {
            ok &= (i[l] || j[l] || k[l]);
        }
        res |= ok;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    V<V<int>> as(n,V<int>(5));
    cin >> as;

    int l = 0, r = INF;
    while(r-l > 1) {
        int mid = (l+r)/2;
        if(f(mid,as)) l = mid;
        else r = mid;
    }
    cout << l << endl;
}
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N=55;
int n,a[N],X[N],x;
int dp[N][2];

int calc(int i,int carry)
{
    if(i==n+1) return carry^1;
    int &res=dp[i][carry];
    if(res!=-1) return res;
    int lim=a[i+1]/a[i];
    int cur=X[i]+carry;
    if(cur==lim) res=calc(i+1,1);
    else if(cur==0) res=calc(i+1,0);
    else res=calc(i+1,0)+calc(i+1,1);
    return res;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    memset(dp,-1,sizeof dp);
    cin>>n>>x;
    for(int i=1;i<=n;i++) cin>>a[i];
    a[n+1]=1e18;
    for(int i=n;i>=1;i--)
    {
        X[i]=x/a[i];
        x%=a[i];
    }
    cout<<calc(1,0);
}
