#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> need(n);
  for (auto& i : need) {
    cin >> i;
  }
  vector<int> have(n);
  for (auto& i : have) {
    cin >> i;
  }
  vector<int> add(n);
  vector<pair<int, int> > can(n);
  for (int i = 0; i < n; i++) {
    add[i] = (need[i] - have[i] % need[i]);
    can[i] = {have[i] / need[i], i};
  }
  sort(can.begin(), can.end());
  int l = 0;
  int r = 1e9 + 1;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    long long all = mid;
    int amount = (have[can[0].second] + mid) / need[can[0].second];
    for (int i = 1; i < n; i++) {
      if (can[i].first < amount) {
        all += add[can[i].second];
        all += need[can[i].second] * 1LL * (amount - can[i].first - 1);
      }
    }
    if (all > k) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << (l + have[can[0].second]) / need[can[0].second];
}
