//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]; } ll maine = 3e18; if (M >= 0) { vector dp(300000, (ll)3e18); dp[0] = 0; for (int i = 0; i < N; i++) { for (int x = 0; x <= 290000; x++) { dp[x + A[i]] = min(dp[x + A[i]], dp[x] + 1ll); } } for (int i = M % A.back(); i < 290000; i += A.back()) { if (i > M) break; maine = min(maine, dp[i] + (M - i) / A.back()); } } cout << (maine > (ll)(2e18) ? -1 : maine) << endl; }