#include #include #include #include using namespace std; using ll = long long; const long long INF = 1LL << 60; // 1.15x10^18 template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { int n; ll m; cin >> n >> m; vector a(n); for (int &ai: a) cin >> ai; vector k(n); for (ll &ki: k) cin >> ki; ll tot = inner_product(a.begin(), a.end(), k.begin(), 0LL); if (tot < m) { cout << -1 << endl; return 0; } const int ma = a.back() * a.back(); vector dp(ma + 1, INF); dp[0] = 0; for (int ai: a) for (int j = ai; j <= ma; j++) chmin(dp[j], dp[j - ai] + 1); ll otsuri = tot - m; ll c = max(0LL, (otsuri - ma + a.back()) / a.back()); if (dp[otsuri - c * a.back()] == INF) { cout << -1 << endl; } else { cout << c + dp[otsuri - c * a.back()] << endl; } return 0; }