#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 50;
long long a[maxn];
long long txm[maxn];
long long n, k;
bool test(long long mayk)
{
    memcpy(txm, a, sizeof(a));
    sort(txm + 1, txm + 1 + mayk);
    long long nowmax = 0;
    bool fl = 0;
    if (mayk & 1) fl = 1;
    //  cout<<mayk<<endl;
    //   cout<<txm[1]<<txm[2]<<txm[3]<<txm[4]<<txm[5]<<endl;
    for (int i = mayk; i >= 1; i -= 2)
    {
        if (i == 1 && fl == 1) break;
        long long q1 = txm[i], q2 = txm[i + 1];
        nowmax = max(nowmax + q1, nowmax + q2);
        if (nowmax > k) return false;
    }
    if (fl)
    {
        if (nowmax + txm[1] > k) return false;
    }
    return true;
}
int main()
{
    scanf("%lld%lld", &n, &k);
    for (int i = 1; i <= n; i++)
    {
        scanf("%lld", &a[i]);
    }
    long long l = 0, r = n + 1;
    long long mid = (l + r) / 2;
    while (l + 1 < r)
    {
        mid = (l + r) / 2;
        if (test(mid))
            l = mid;
        else
            r = mid;
    }
    printf("%lld\n", l);
    return 0;
}