#include <bits/stdc++.h>
using namespace std;
bool solve(long long m, const vector<long long> &a, const vector<long long> &b,
           long long k, int n) {
  for (int i = 0; i < n; i++) {
    k -= max(0ll, m * a[i] - b[i]);
    if (k < 0) return 0;
  }
  return k >= 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  long long lo = 0, hi = 0;
  for (int i = 0; i < n; i++) hi = max(hi, (b[i] + k) / a[i]);
  hi++;
  while (hi - lo > 1) {
    long long mid = lo + (hi - lo) / 2;
    if (solve(mid, a, b, k, n))
      lo = mid;
    else
      hi = mid;
  }
  cout << lo << '\n';
  return 0;
}
