#include <bits/stdc++.h>
using namespace std;
long long a[100001], b[100001], n;
int ok(long long mid, long long k) {
  for (int i = 1; i <= n; i++) {
    long long res = mid * a[i];
    res = b[i] - res;
    if (res >= 0) continue;
    k += res;
    if (k < 0) return 0;
  }
  return 1;
}
int main() {
  long long k, ans = 0;
  cin >> n >> k;
  pair<long long, long long> t;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  long long lo = 1, hi = 10000000000;
  while (lo <= hi) {
    long long mid = (lo + hi) / 2;
    if (ok(mid, k)) {
      ans = mid;
      lo = mid + 1;
    } else
      hi = mid - 1;
  }
  cout << ans;
  return 0;
}
