#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> b(n);
  for (int i = 0; i < n; i++) cin >> b[i];
  vector<pair<int, int> > r(n);
  for (int i = 0; i < n; i++) r[i] = make_pair(b[i] / a[i], i);
  sort(r.begin(), r.end());
  int am = r[0].first;
  int add = 0;
  int rest = 0;
  for (int i = 0; i < n; i++) {
    int j = r[i].second;
    if (r[i].first == am) {
      add += a[j] - b[j] % a[j];
      rest += b[j] % a[j];
    } else {
      if (k > 0 && am != r[i].first) {
        k -= add;
        if (k >= 0) am++;
        add += rest;
        rest = 0;
        if (k > (r[i].first - am) * add) {
          k -= (r[i].first - am) * add;
          am = r[i].first;
        } else {
          am += k / add;
          k -= (k / add) * add;
        }
      }
      rest = b[j] % a[j];
      add += a[j] - b[j] % a[j];
    }
  }
  if (k > 0) {
    k -= add;
    if (k >= 0) am++;
    add += rest;
    rest = 0;
    am += k / add;
  }
  cout << am << endl;
  return 0;
}
