#include #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define FORR(i,a,b) for (int i=(a);i>=(b);i--) #define pb push_back using namespace std; typedef long long ll; typedef pair pii; typedef vector vi; typedef set si; const ll inf = 1e18; const int mod = 1e9+7; ll dp[250001]; ll n, m, a[500], k[500], q; main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m; FOR(i, 0, n)cin >> a[i]; FOR(i, 0, n)cin >> k[i]; q = a[n - 1]; q *= q; FOR(i, 1, q)dp[i] = inf; m *= -1; FOR(i, 0, n)m += a[i] * k[i]; if(m < 0){ cout << -1 << endl; return 0; } FORR(i, n-1, 0){ ll d = a[i]; FOR(j, d, q){ dp[j] = min(dp[j], dp[j - d] + 1); } } ll t = 0; if(m >= q){ t = (m - q)/a[n-1] + 1; m -= t * a[n-1]; } t += dp[m]; if(t >= inf)t = -2; cout << t << endl; //FOR(i, 0, q)cout << i << ":" << dp[i] << endl; }