#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 5;
long long n, k, cook[N], have[N];
long long ok(long long num) {
  bool flag = 0;
  long long mag = k;
  for (int i = 0; i < n; i++) {
    if (have[i] < num * cook[i]) {
      if (mag < (num * cook[i]) - have[i]) {
        return 0;
      } else
        mag -= (num * cook[i]) - have[i];
    }
  }
  return 1;
}
long long binary_Search() {
  long long lo = 0, mid, hi = 2e9;
  while (hi - lo > 0) {
    mid = (lo + hi + 1) / 2;
    if (ok(mid)) {
      lo = mid;
    } else
      hi = mid - 1;
  }
  return lo;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &cook[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &have[i]);
  }
  int ans = binary_Search();
  cout << ans;
  return 0;
}
