#include <bits/stdc++.h>
using namespace std;
unsigned long long a[1000010], b[1000010];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  unsigned long long n, k;
  cin >> n >> k;
  for (unsigned long long i = 0; i < n; i++) cin >> a[i];
  for (unsigned long long i = 0; i < n; i++) cin >> b[i];
  unsigned long long l = 0;
  unsigned long long h = 2e9;
  unsigned long long ans = 0;
  while (l <= h) {
    unsigned long long mid = (l + h) / 2;
    unsigned long long temp = 0;
    for (unsigned long long i = 0; i < n; i++) {
      temp += mid * a[i] - min(mid * a[i], b[i]);
      if (temp > k) break;
    }
    if (temp > k)
      h = mid - 1;
    else {
      l = mid + 1;
      ans = mid;
    }
  }
  cout << ans << "\n";
  return 0;
}
