#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T v) {
    cout << v << " ";
    return *this;
  }
} dbg;
const double pi = acos(-1.0);
const double eps = 1e-7;
template <class TT>
TT sqr(TT a) {
  return a * a;
}
template <class TT>
TT abs(TT a) {
  if (a < 0) return -a;
  return a;
}
const int S = 100010;
long long r[S];
long long h[S];
int main() {
  long long n, k, ans;
  while (scanf("%I64d%I64d", &n, &k) == 2) {
    for (int i = 0; i < n; i++) scanf("%I64d", r + i);
    for (int i = 0; i < n; i++) scanf("%I64d", h + i);
    ans = (1LL << 34);
    for (int i = 0; i < n; i++) {
      ans = min(ans, h[i] / r[i]);
    }
    for (int i = 0; i < n; i++) h[i] -= r[i] * ans;
    long long low = 0;
    long long hi = pow(10, 9);
    long long mid = 0;
    while (low < hi) {
      mid = (low + hi + 1) / 2;
      long long req = 0;
      for (int i = 0; i < n; i++) req += max(0LL, mid * r[i] - h[i]);
      if (req <= k) {
        low = mid;
      } else
        hi = mid - 1;
    }
    printf("%I64d\n", ans + low);
  }
  return 0;
}
