#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n, k, a[N], b[N];
bool check(long long mid) {
  long long with = k;
  for (int i = 0; i < n; ++i) {
    long long need = max(0LL, 1LL * a[i] * mid - b[i]);
    with -= need;
    if (with < 0) return false;
  }
  return true;
}
int main(int argc, char **argv) {
  scanf("%d%d", &n, &k);
  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 = 4e9, res = 0;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (check(mid)) {
      res = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  printf("%lld\n", res);
  return 0;
}
