#include <bits/stdc++.h>
using namespace std;
inline unsigned long long max_(unsigned long long a, unsigned long long b) {
  return (a > b) ? a : b;
}
inline unsigned long long min_(unsigned long long a, unsigned long long b) {
  return (a < b) ? a : b;
}
unsigned long long n, k, a[100005], b[100005];
bool possible(unsigned long long m) {
  unsigned long long i, req = 0ULL;
  for (i = 0; i < n; i++) {
    if (m * a[i] > b[i]) req += (m * a[i] - b[i]);
  }
  return (req <= k);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  if (fopen("inp.txt", "r")) {
    freopen("inp.txt", "r", stdin);
    freopen("outp.txt", "w", stdout);
  }
  cin >> n >> k;
  unsigned long long i;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) cin >> b[i];
  unsigned long long l = 0, h = (1ULL << 45ULL), ans = 0ULL;
  while (l <= h) {
    unsigned long long m = l + ((h - l) >> 1ULL);
    if (possible(m)) {
      ans = m;
      l = m + 1;
    } else {
      h = m - 1;
    }
  }
  cout << ans << endl;
  return 0;
}
