#include <bits/stdc++.h>
using namespace std;
long long a[1000000];
long long b[1000000];
int main() {
  long long n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int j = 0; j < n; ++j) {
    cin >> b[j];
  }
  long long lo = 0, hi = (1LL << 31), ans = -1;
  while (lo <= hi) {
    long long mid = (lo + hi) / 2;
    long long req = 0;
    bool ok = true;
    for (int i = 0; i < n; ++i) {
      req += max(a[i] * mid - b[i], 0LL);
      if (req > k) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans = mid;
      lo = mid + 1;
    } else {
      hi = mid - 1;
    }
  }
  cout << ans << endl;
}
