//https://ncode.syosetu.com/n4830bu/288/ #include using namespace std; using ll = long long; int main() { ll N, M; cin >> N >> M; vector A(N), K(N); for (auto&& a : A) { cin >> a; } for (auto&& k : K) { cin >> k; } M *= -1; for (int i = 0; i < N; i++) { M += A[i] * K[i]; } vector dp(610000, (ll)1e18 + 10); dp[0] = 0; ll maine = 1; while (M) { for (int i = 0; i < N; i++) { for (int x = 600000; x >= 0; x--) { dp[x + A[i]] = min(dp[x + A[i]], dp[x] + maine); } } for (int i = 0; i < 300000; i++) { dp[i] = dp[i * 2 + M % 2ll]; } fill(dp.begin() + 300000, dp.end(), (ll)1e18 + 10); M >>= 1; maine <<= 1; } cout << (dp[0] > (ll)1e18 ? -1 : dp[0]) << endl; }