#include <bits/stdc++.h>
using namespace std;

int n, t, a[100];
vector<int> l, r;

void dfs(int dep, int sum) {
	if (sum > t) return;
	if (dep > (n >> 1)) {
		l.push_back(sum);
		return;
	}
	dfs(dep + 1, sum);
	dfs(dep + 1, sum + a[dep]);
}

void dfs2(int dep, int sum) {
	if (sum > t) return;
	if (dep > n) {
		r.push_back(sum);
		return;
	}
	dfs2(dep + 1, sum);
	dfs2(dep + 1, sum + a[dep]);
}

int main(void) {
	scanf("%d%d", &n, &t);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
	}
	dfs(1, 0);
	dfs2((n >> 1) + 1, 0);
	sort(r.begin(), r.end());
	int ans = 0;
	for (auto i : l) {
		ans = max(ans, i + *(upper_bound(r.begin(), r.end(), t - i) - 1));
	}
	printf("%d\n", ans);
	return 0;
}

#include <algorithm>
#include <iostream>
#include <cstring>

using namespace std;

char cc[64];

int maxdigit(int n) {
	return n == 0 ? 0 : max(maxdigit(n - 1), cc[n - 1] - '0');
}

bool ok(int n, long long b, long long m) {
	long long x = 0;
	for (int i = 0; i < n; i++) {
		if (x > (m - (cc[i] - '0')) / b)
			return false;
		x = x * b + cc[i] - '0';
	}
	return true;
}

int main() {
	long long m; cin >> cc >> m;
	int n = strlen(cc);
	if (n == 1) {
		cout << (cc[0] - '0' <= m ? 1 : 0) << '\n';
		return 0;
	}
	int d = maxdigit(n);
	long long lower = d, upper = m + 1;
	while (upper - lower > 1) {
		long long b = (lower + upper) / 2;
		if (ok(n, b, m))
			lower = b;
		else
			upper = b;
	}
	long long b = lower;
	cout << b - d << '\n';
	return 0;
}
