#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, oo = 0x3f3f3f3f;
long long n, A[N], B[N], k;
bool ok(long long x) {
  long long mokwn = k;
  for (int i = 0; i < n; ++i) {
    long long neededpowder = A[i] * x - B[i];
    if (neededpowder > 0) {
      mokwn -= neededpowder;
      if (mokwn < 0) return false;
    }
  }
  return true;
}
long long binarySearch() {
  long long lo = 0, med, hi = 2e9 + 5;
  while (lo < hi) {
    med = (lo + hi + 1) >> 1;
    if (ok(med))
      lo = med;
    else
      hi = med - 1;
  }
  return lo;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> A[i];
  for (int i = 0; i < n; ++i) cin >> B[i];
  cout << binarySearch();
  return 0;
}
