#include <bits/stdc++.h>
using namespace std;
bool check(vector<int> &a, vector<int> &b, int n, int k, long long mid) {
  long long need = 0;
  for (int i = 0; i < n; i++) {
    need += max(0ll, 1ll * a[i] * mid - b[i]);
    if (need > 1ll * k) return false;
  }
  return true;
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n; i++) scanf("%d", &b[i]);
  long long l = 1, r = 2e9, ans = 0;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (check(a, b, n, k, mid)) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  printf("%lld\n", ans);
  return 0;
}
