#include <bits/stdc++.h>
using namespace std;
int a[100000];
int b[100000];
bool judge(long long x, int n, long long k) {
  for (int i = 0; i < n; ++i) {
    k -= max(0LL, a[i] * x - b[i]);
    if (k < 0) {
      return false;
    }
  }
  return true;
}
int main(void) {
  int n, k;
  assert(scanf("%d%d", &n, &k) == 2);
  for (int i = 0; i < n; ++i) {
    assert(scanf("%d", &a[i]) == 1);
  }
  for (int i = 0; i < n; ++i) {
    assert(scanf("%d", &b[i]) == 1);
  }
  long long l = 0, r = 2000000001;
  while (r - l > 1) {
    long long m = (l + r) / 2;
    if (judge(m, n, k)) {
      l = m;
    } else {
      r = m;
    }
  }
  printf("%I64d\n", l);
  return 0;
}
