#include <bits/stdc++.h>
long long a[100005], b[100005];
long long n, k;
int check(long long min) {
  long long d = k;
  for (int i = 0; i < n; i++) {
    if (a[i] * min <= b[i])
      continue;
    else {
      d -= a[i] * min - b[i];
    }
    if (d < 0) return 0;
  }
  return 1;
}
int main() {
  long long l, r, ans, min = 10000000000, max = 0, mid;
  scanf("%lld %lld", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%lld", &b[i]);
    if (b[i] / a[i] < min) min = b[i] / a[i];
    if (b[i] / a[i] > max) max = b[i] / a[i];
  }
  max += k;
  l = min;
  r = max;
  ans = min;
  while (l <= r) {
    mid = (l + r) / 2;
    if (check(mid)) {
      l = mid + 1;
      ans = mid;
    } else {
      r = mid - 1;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
