#include <bits/stdc++.h>
long long a[100000];
long long b[100000];
int main() {
  long long n, k;
  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]);
  }
  long long ans = 0;
  long long m = 1000000000;
  for (int i = 0; i < n; i++) {
    m = std::min(m, b[i] / a[i]);
  }
  ans += m;
  for (int i = 0; i < n; i++) {
    b[i] -= m * a[i];
  }
  long long left = 0;
  long long right = 1000000000;
  long long p = 0;
  while (left <= right) {
    long long mid = (left + right) / 2;
    long long q = k;
    for (int i = 0; i < n; i++) {
      if (a[i] * mid > b[i]) {
        q -= a[i] * mid - b[i];
      }
      if (q < 0) {
        break;
      }
    }
    if (q >= 0) {
      p = std::max(p, mid);
      left = mid + 1;
    } else {
      right = mid - 1;
    }
  }
  printf("%lld", ans + p);
}
