#include <bits/stdc++.h>

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;
typedef long long LL;

const int MAXN = 55;
const int MOD = 1E9 + 7;
LL n, x, a[MAXN], g[MAXN], dp[MAXN][2];

template <class T>
void read(T& x) {
    x = 0;
    T f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

template <class T, class... Args>
void read(T& x, Args&... args) {
    read(x), read(args...);
}

signed main() {
    read(n, x);
    for (int i = 1; i <= n; i++) read(a[i]);
    for (int i = n; i >= 1; i--) {
        if (!x) break;
        g[i] = x / a[i], x %= a[i];
    }
    for (int i = n - 1; i >= 1; i--) {
        LL lim = a[i + 1] / a[i];
        if (g[i] == 0) {
            dp[i][0] = dp[i + 1][0];
            dp[i][1] = dp[i + 1][1] + dp[i + 1][0] + 1;
        } else if (g[i] == lim - 1) {
            dp[i][0] = dp[i + 1][0] + dp[i + 1][1] + 1;
            dp[i][1] = dp[i + 1][1];
        } else {
            dp[i][1] = dp[i + 1][1] + dp[i + 1][0] + 1;
            dp[i][0] = dp[i + 1][0] + dp[i + 1][1] + 1;
        }
    }
    cout << dp[1][0] + 1;
    return 0;
}
/**
*    author: Dooloper
*    created: 01.05.2021 20:57:29
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repp(i,k, n) for(int i = (int)(k); i < (int)(n); i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using P = pair<int, int>;
struct Edge{int to; ll w; Edge(int to, ll w) : to(to), w(w) {}};
using Graph = vector<vector<Edge>>;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int n;
vector<vector<int>> x(3030, vector<int>(5));

int getMask(int i, int lim){
    int res = 0;
    rep(j,5) if(lim <= x[i][j]) res += 1 << j;
    return res;
}

vector<int> cnt(1<<5);

bool check(int lim){
    rep(i, 1<<5) cnt[i] = 0;
    rep(i,n) cnt[getMask(i,lim)]++;
    rep(msk1,1 << 5) rep(msk2,1<<5) rep(msk3,1<<5) {
        if((msk1 | msk2 | msk3) == (1<<5)-1 && 0 < cnt[msk1] && 0 < cnt[msk2] && 0 < cnt[msk3]) return true;
    }
    return false;
}

int main(){
    cin >> n;
    rep(i,n) rep(j,5) cin >> x[i][j];

    int ok = 0; int ng = 1000000007;
    while(ok + 1 != ng){
        int md = (ok+ng)/2;
        if(check(md)) ok = md;
        else ng = md;
    }
    cout << ok << endl;
    
}