#include <bits/stdc++.h>
const long long maxn = 8e9 + 5;
long long v[10000000];
long long k[10000000];
long long n, sum;
int judge(long long m) {
  long long i, sum1 = sum;
  for (i = 0; i < n; i++) {
    if (m * v[i] > k[i]) {
      if (k[i] + sum1 < m * v[i])
        break;
      else if (k[i] + sum1 >= m * v[i])
        sum1 = sum1 + k[i] - m * v[i];
    }
  }
  if (i < n)
    return 0;
  else
    return 1;
}
int main() {
  long long l, r, mid;
  scanf("%I64d%I64d", &n, &sum);
  for (long long i = 0; i < n; i++) {
    scanf("%I64d", &v[i]);
  }
  for (long long i = 0; i < n; i++) {
    scanf("%I64d", &k[i]);
  }
  l = 0;
  r = maxn;
  while (l + 1 < r) {
    mid = l + (r - l) / 2;
    if (judge(mid)) {
      l = mid;
    } else
      r = mid;
  }
  if (judge(l + 1))
    printf("%I64d", l + 1);
  else
    printf("%I64d", l);
}
