#include <bits/stdc++.h>
const int maxn = 1e5;
int n, k;
int a[maxn], b[maxn];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
  long long L = 0;
  long long R = 2e9;
  while (L < R) {
    long long M = (L + R + 1) >> 1;
    long long rem = 0;
    for (int i = 0; i < n; ++i) {
      long long t = 1ll * a[i] * M;
      if (t > b[i]) {
        rem += t - b[i];
        if (rem > k) rem = k + 1;
      }
    }
    if (rem <= k)
      L = M;
    else
      R = M - 1;
  }
  printf("%I64d\n", L);
  return 0;
}
