#include <bits/stdc++.h>
using namespace std;
long long n, k, a[100009], b[100009], maxi = 0, ans = 0;
bool chk(long long tot, long long cap) {
  long long tmp, ex;
  for (long long i = 1; i <= n; i++) {
    tmp = tot * a[i];
    if (tmp <= b[i]) {
      continue;
    } else {
      ex = tmp - b[i];
      if (cap >= ex) {
        cap = cap - ex;
        continue;
      } else {
        return 0;
      }
    }
  }
  return 1;
}
int main() {
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &b[i]);
    maxi = max(maxi, (b[i] + k) / a[i]);
  }
  long long lo, hi, mid;
  lo = 0;
  hi = maxi + 100;
  while (hi - lo > 2) {
    mid = (lo + hi) / 2;
    if (chk(mid, k) == 1) {
      lo = mid;
    } else {
      hi = mid - 1;
    }
  }
  for (long long i = lo; i <= hi; i++) {
    if (chk(i, k) == 1) {
      ans = i;
    }
  }
  cout << ans << endl;
}
