#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, g;
  cin >> n >> g;
  long long a[n + 1], b[n + 1], d[n + 1];
  long long ans = 0;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) cin >> b[i];
  long long start = 0;
  long long ends = 2000000005, s, sum = 0;
  while (start <= ends) {
    sum = 0;
    long long mid = (start + ends) / 2;
    for (int i = 0; i < n; i++) {
      s = (mid * a[i]);
      if (s > b[i]) sum += (s - b[i]);
      if (sum > g) break;
    }
    if (sum <= g) {
      ans = max(mid, ans);
      start = mid + 1;
    } else {
      ends = mid - 1;
    }
  }
  cout << ans << "\n";
}
