#include <bits/stdc++.h>
using namespace std;
unsigned long long i, n, k, a[100001], b[100001];
unsigned long long solve(unsigned long long val) {
  unsigned long long cnt = 0;
  for (i = 0; i < n; i++) {
    if (a[i] * val > b[i]) cnt += val * a[i] - b[i];
  }
  if (cnt > k) return 0;
  return 1;
}
unsigned long long binarysearch(unsigned long long l, unsigned long long r) {
  unsigned long long mid, ans = 0;
  while (l <= r) {
    mid = (l + r) / 2;
    if (solve(mid)) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return ans;
}
int main() {
  cin >> n >> k;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) cin >> b[i];
  unsigned long long l, r;
  l = 0;
  r = 0;
  for (int i = 0; i < n; i++) r = max((b[i] + k) / a[i], r);
  cout << binarysearch(l, r) << endl;
  return 0;
}
