#include <bits/stdc++.h>
using namespace std;
struct info {
  long long int how, rem;
  long long int need, has;
  void setInfo() {
    how = has / need;
    rem = has % need;
  }
  bool operator<(const info &b) const { return how < b.how; }
};
long long int n, k;
info ara[100005];
bool isPossible(long long int num) {
  long long int rem = k;
  for (int i = 0; i < n; i++) {
    if (ara[i].how >= num) return true;
    long long int dif = num - ara[i].how;
    rem -= (dif * ara[i].need - ara[i].rem);
    if (rem < 0) return false;
  }
  return true;
}
int main() {
  scanf("%lld %lld", &n, &k);
  long long int tmp;
  for (int i = 0; i < n; i++) {
    scanf("%lld", &tmp);
    ara[i].need = tmp;
  }
  for (int i = 0; i < n; i++) {
    scanf("%lld", &tmp);
    ara[i].has = tmp;
  }
  for (int i = 0; i < n; i++) {
    ara[i].setInfo();
  }
  sort(ara, ara + n);
  long long int hi = 1e10, lo = ara[0].how;
  long long int mid, ans;
  while (lo <= hi) {
    mid = (lo + hi) / 2;
    if (isPossible(mid)) {
      ans = mid;
      lo = mid + 1;
    } else {
      hi = mid - 1;
    }
  }
  printf("%lld\n", ans);
}
