#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k, l = 0, r = 0;
  cin >> n >> k;
  long long a[n], b[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
    long long val = (b[i] + k) / a[i];
    r = max(r, val);
  }
  long long ans = 0;
  while (l <= r) {
    long long mid = l + (r - l) / 2;
    int p = k;
    for (long long i = 0; i < n; i++) {
      if (a[i] * mid > b[i]) p -= a[i] * mid - b[i];
      if (p < 0) break;
    }
    if (p < 0)
      r = mid - 1;
    else {
      ans = max(ans, mid);
      l = mid + 1;
    }
  }
  cout << ans;
  return 0;
}
