#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
int N, K, a[maxn], b[maxn];
bool solve(int tar) {
  long long cur = K;
  for (int i = 1; i <= N; ++i) {
    long long ex = 1LL * b[i] - 1LL * tar * a[i];
    if (ex < 0) cur += ex;
    if (cur < 0) return false;
  }
  return true;
}
int main(int argc, char *argv[]) {
  scanf("%d%d", &N, &K);
  for (int i = 1; i <= N; ++i) scanf("%d", a + i);
  for (int i = 1; i <= N; ++i) scanf("%d", b + i);
  int l = 0, r = 2e9;
  while (l < r) {
    int mid = l + (r - l + 1) / 2;
    if (solve(mid))
      l = mid;
    else
      r = mid - 1;
  }
  printf("%d\n", l);
  return 0;
}
