#include <bits/stdc++.h>
using namespace std;
long long need[100005];
long long m3aya[100005];
long long n, k;
bool ok(long long mid) {
  long long num = k;
  for (long long i = 0; i < n; i++) {
    long long needed = need[i] * mid;
    if (m3aya[i] < needed) {
      if (needed - m3aya[i] > num)
        return false;
      else
        num -= (needed - m3aya[i]);
    }
  }
  return true;
}
long long bsearch() {
  long long l = 0;
  long long r = 3000000000;
  while (l < r) {
    long long mid = l + (r - l + 1) / 2;
    if (ok(mid))
      l = mid;
    else
      r = mid - 1;
  }
  return l;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) scanf("%lld", &need[i]);
  for (int i = 0; i < n; i++) scanf("%lld", &m3aya[i]);
  cout << bsearch() << endl;
}
