#include <bits/stdc++.h>
using namespace std;
const long long int e = 1e9 + 9;
long long int arr[100005], arr2[100005], powder, n;
bool make_cake(long long int ncakes) {
  long long int k = powder;
  for (int z = 0; z < n; z++) {
    if (arr2[z] < arr[z] * ncakes) {
      if (k < ((arr[z] * ncakes) - arr2[z])) return 0;
      k -= ((arr[z] * ncakes) - arr2[z]);
    }
  }
  return 1;
}
long long int BinarySearch() {
  long long int low = 0, high = 2e9, mid = 0;
  while (high - low > 0) {
    mid = (high + low + 1) / 2;
    if (make_cake(mid))
      low = mid;
    else
      high = mid - 1;
  }
  return low;
}
int main() {
  scanf("%lld%lld", &n, &powder);
  for (int i = 0; i < n; i++) scanf("%lld", arr + i);
  for (int i = 0; i < n; i++) scanf("%lld", arr2 + i);
  printf("%lld\n", BinarySearch());
  return 0;
}
