#include <bits/stdc++.h>
using namespace std;
long long A[100002], B[100002], C[100002];
bool can(long long k, long long Mid, long long n) {
  long long need = 0;
  for (long long i = 0; i < n; i++) {
    if (Mid * A[i] > B[i]) {
      need += Mid * A[i] - B[i];
    }
    if (need > k) return false;
  }
  return (need <= k);
}
int main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> A[i];
  for (long long i = 0; i < n; i++) cin >> B[i];
  for (long long i = 0; i < n; i++) C[i] = B[i] / A[i];
  long long cn = *min_element(C, C + n);
  long long ans = 0;
  if (cn > 0) {
    ans += cn;
    for (long long i = 0; i < n; i++) {
      B[i] -= A[i] * cn;
    }
  }
  long long L = 0, R = 1e9 + 1;
  long long Mid;
  while (L != R) {
    Mid = (L + R) / 2;
    if (can(k, Mid, n) && !can(k, Mid + 1, n)) {
      ans += Mid;
      break;
    } else if (!can(k, Mid, n)) {
      R = Mid;
    } else {
      L = Mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
