#include #define GET_MACRO(a, b, c, NAME, ...) NAME #define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__) #define rep2(i, a) rep3 (i, 0, a) #define rep3(i, a, b) for (int i = (a); i < (b); i++) #define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__) #define repr2(i, a) repr3 (i, 0, a) #define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--) #define chmin(a, b) ((b) < a && (a = (b), true)) #define chmax(a, b) (a < (b) && (a = (b), true)) using namespace std; typedef long long ll; const ll inf = 1e9; const ll MX = 333333; ll N, M; ll A[500], K[500]; int dp[2][MX]; ll solve(ll D) { rep (i, 2) rep (j, MX) dp[i][j] = inf; dp[0][0] = 0; rep (i, N) { rep (j, MX) { dp[(i + 1) % 2][j] = dp[i % 2][j]; if (j - A[i] >= 0) { chmin(dp[(i + 1) % 2][j], dp[(i + 1) % 2][j - A[i]] + 1); } } } if (D < MX) { if (dp[N % 2][D] == inf) return -1; return dp[N % 2][D]; } else { ll mx = *max_element(A, A + N); ll num = (D - MX + mx - 1) / mx; ll res = dp[N % 2][D - num * mx] + num; return res; } } int main() { cin >> N >> M; rep (i, N) cin >> A[i]; rep (i, N) cin >> K[i]; ll mx = 0; rep (i, N) mx += A[i] * K[i]; ll D = mx - M; if (D < 0) { cout << -1 << endl; } else { ll ans = solve(D); cout << ans << endl; } return 0; }