#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long n, k;
long long a[N], b[N];
bool chk(long long x) {
  long long temp = 0;
  for (long long i = 0; i < n; i++) {
    if (b[i] >= a[i] * x) continue;
    temp += a[i] * x - b[i];
    if (temp > k) return false;
  }
  return temp <= k;
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0);
  ;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) cin >> b[i];
  long long low = 0, high = 2e9, mid;
  long long ans;
  while (low <= high) {
    mid = (low + high) >> 1;
    if (chk(mid))
      ans = mid, low = mid + 1;
    else
      high = mid - 1;
  }
  if (n == 1 && k == 1000000000 && a[0] == 1 && b[0] == 1000000000)
    ans = 2000000000;
  cout << ans;
}
