#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; const ll INF = numeric_limits::max(); ll N, M, A[500], K[500]; void solve(){ ll r = -M; rep(i, N)r += A[i] * K[i]; if(r < 0){ puts("-1"); return; } ll ans = 0; if(r >= A[N - 1] * A[N - 1]){ ans += (r-A[N-1]*A[N-1]) / A[N-1]; r -= ans * A[N-1]; } vll dp(r+1, INF); dp[0] = ans; rep(i, N){ ll a = A[i], m = r / a; for(ll x = 1; m; x <<= 1){ ll y = min(m, x); m -= y; for(int j = (int)r; j >= 0; --j)if(dp[j]!=INF && j + y*a <= r){ smin(dp[j + y*a], dp[j] + y); } } } cout << (dp.back() == INF ? -1 : dp.back()) << endl; } int main(){ while(cin >> N >> M){ rep(i, N)scanf("%lld", &A[i]); rep(i, N)scanf("%lld", &K[i]); solve(); } }