#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long exp, long long mod = (1000000007LL)) {
  long long res = 1;
  while (exp > 0) {
    if (exp % 2) {
      res = (res * base) % mod;
    }
    base = (base * base) % mod;
    exp /= 2;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    gcd(b, a % b);
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
inline string rs() {
  char x[1234567];
  scanf("%s", x);
  string s = x;
  return s;
}
inline int ri() {
  int x;
  scanf("%d", &x);
  return x;
}
inline long long rl() {
  long long x;
  scanf("%lld", &x);
  return x;
}
const int N = 1234567;
long long n, k;
long long req[N], have[N];
bool enough(long long cookies) {
  long long need = 0;
  for (int i = 0; i < n; i++) {
    long long ingredient_need = req[i] * cookies;
    need += max(0LL, ingredient_need - have[i]);
    if (need > k) return true;
  }
  return false;
}
int main() {
  scanf("%lld %lld", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld", req + i);
  }
  for (int i = 0; i < n; i++) {
    scanf("%lld", have + i);
  }
  long long lo = 0, hi = (long long)(2e9 + 500);
  while (lo < hi) {
    long long mid = (lo + hi) >> 1;
    if (enough(mid)) {
      hi = mid;
    } else {
      lo = mid + 1;
    }
  }
  printf("%lld\n", lo - 1);
  return 0;
}
