#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long n, a[N], b[N], k;
bool ok(long long m) {
  long double nd = 0;
  for (int i = 0; i < n; i++) nd += max(0ll, b[i] * m - a[i]);
  return nd <= k;
}
int main() {
  scanf("%lld %lld", &n, &k);
  for (int i = 0; i < n; i++) scanf("%lld", b + i);
  for (int i = 0; i < n; i++) scanf("%lld", a + i);
  long long lo = 0, hi = 1e10, mid;
  while (lo < hi) {
    mid = (hi + lo + 1) >> 1;
    if (ok(mid)) {
      lo = mid;
    } else {
      hi = mid - 1;
    }
  }
  printf("%lld", hi);
  return 0;
}
