#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 = 1e18; const ll MX = 101010; ll N, M; ll A[500], K[500]; ll dp[505][MX]; ll solve(ll D) { rep (i, 505) rep (j, MX) dp[i][j] = inf; dp[0][0] = 0; rep (i, N) { rep (j, MX) { chmin(dp[i + 1][j], dp[i][j]); if (j - A[i] >= 0) { chmin(dp[i + 1][j], dp[i + 1][j - A[i]] + 1); } } } if (D < MX) { return dp[N][D]; } else { ll mx = *max_element(A, A + N); ll num = (D - MX) / mx; D -= num * mx; return dp[N][D] + num; } } 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 mn = 0; repr (i, N) if (K[i] != 0) mn = A[i]; ll D = mx - M; if (D < 0) { cout << -1 << endl; } else { ll ans = solve(D); if (ans >= inf) { cout << -1 << endl; } else { cout << ans << endl; } } return 0; }