#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 5;
int n;
long long k;
int A[MAX_N];
int B[MAX_N];
void solve() {
  int i = 0;
  long long sum1 = 0LL;
  for (i = 0; i < n; i++) sum1 += max(0, A[i] - B[i]);
  long long lo = 0, hi = 2e12, ans = 0;
  for (i = 0; i < n; i++)
    hi = min(hi, (long long)(2e9 + (long long)B[i]) / A[i]);
  while (lo <= hi) {
    long long mid = (lo + hi) >> 1;
    long long sum = 0;
    for (i = 0; i < n; i++) sum += max(A[i] * mid - B[i], 0LL);
    if (sum <= k) {
      ans = mid;
      lo = mid + 1;
    } else
      hi = mid - 1;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int test = 1;
  while (test--) {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> A[i];
    for (int i = 0; i < n; i++) cin >> B[i];
    solve();
  }
  return 0;
}
