#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int t = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') f = (ch == '-') ? -1 : f, ch = getchar();
  while (ch >= '0' && ch <= '9') t = t * 10 + ch - '0', ch = getchar();
  return t * f;
}
int n, m;
int a[101010], w[101010];
bool test(int x) {
  long long tmp = m;
  for (int i = 1; i <= n; i++) {
    long long t = w[i] - (long long)x * a[i];
    if (t < 0) tmp += t;
    if (tmp < 0) return 0;
  }
  return 1;
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= n; i++) w[i] = read();
  int l = 0, r = 2e9 + 10, mid, ans;
  while (l <= r) {
    int mid = ((long long)l + r) >> 1;
    if (test(mid))
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%d\n", ans);
  return 0;
}
