#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pl = pair<ll, ll>;
constexpr int MX = 5005, MOD = 998244353;

pl DP[MX][2];

int main() {
	if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
	cin.tie(0)->sync_with_stdio(0);

	int N, M; cin >> N >> M;
	ll ans = 0;
	for (int i = 1; i <= M; ++i) {
		DP[0][0] = pl(0, M-1), DP[0][1] = pl(1, 1);
		for (int j = 0; j < N-1; ++j) {
			DP[j+1][0] = pl((M-1)*DP[j][0].f+(i-1)*DP[j][1].f, (M-1)*DP[j][0].s+(i-1)*DP[j][1].s);
			DP[j+1][1] = pl(DP[j][0].f+DP[j][0].s+(M-i+1)*DP[j][1].f, DP[j][0].s+(M-i+1)*DP[j][1].s);
			DP[j+1][0].f %= MOD, DP[j+1][0].s %= MOD;
			DP[j+1][1].f %= MOD, DP[j+1][1].s %= MOD;
		}
		(ans += DP[N-1][0].f+DP[N-1][1].f) %= MOD;
	}
	cout << ans;
}

#include <bits/stdc++.h>

#define task "F"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
int n, T, a[41];
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n >> T;
    rep(i, 0, n - 1) cin >> a[i];
    vl vec;
    int nn = n / 2;
    rep(x, 0, (1 << nn) - 1)
    {
        ll sum = 0;
        rep(i, 0, nn - 1) if (x >> i & 1) sum += a[i];
        vec.eb(sum);
    }
    sort(all(vec));
    int nn1 = n - nn, ans = 0;
    rep(x, 0, (1 << nn1) - 1)
    {
        ll sum = 0;
        rep(i, 0, nn1 - 1) if (x >> i & 1) sum += a[nn + i];
        auto it = upper_bound(all(vec), T - sum);
        if (it != vec.begin())
        {
            it--;
            ans = max(1ll * ans, *it + sum);
        }
    }
    cout << ans;
    return 0;
}
