#include <bits/stdc++.h>
const long long INF = 2e18;
const double EPS = 1e-9;
using namespace std;
void WEZaa() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  WEZaa();
  unsigned long long n, k;
  cin >> n >> k;
  vector<unsigned long long> a(n), b(n);
  for (auto& i : a) cin >> i;
  for (auto& i : b) cin >> i;
  unsigned long long l = 0, r = 1e10, ans = 0, md;
  while (l <= r) {
    md = (l + r) / 2;
    unsigned long long sum = 0;
    for (int i = 0; i < n; i++) {
      unsigned long long st = a[i] * md;
      if (b[i] < st) sum += st - b[i];
    }
    if (sum <= k)
      l = md + 1, ans = md;
    else
      r = md - 1;
  }
  cout << ans << "\n";
}
