#include <bits/stdc++.h>
using namespace std;
template <typename T>
T sqr(T x) {
  return x * x;
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
const int MAXN = (int)1e5 + 10;
int n;
long long k;
long long a[MAXN];
long long b[MAXN];
long long ans = 2000000007;
pair<long long, long long> x[MAXN];
long long sum[MAXN], cnt = 0;
inline bool cmp(const pair<long long, long long> &l,
                const pair<long long, long long> &r) {
  return (l.first / l.second) < (r.first / r.second);
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int j = 1; j <= n; j++) cin >> b[j], x[j] = make_pair(b[j], a[j]);
  sort(x + 1, x + n + 1, cmp);
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + x[i].second;
  sum[n + 1] = (long long)2000000007 * (2000000007 / 2);
  x[n + 1] = make_pair(sum[n + 1], 1);
  sum[0] = 0;
  long long MOD = 0;
  int lst = 0;
  bool flag = false;
  for (int i = 1; i <= n; i++)
    if (x[i].first / x[i].second < x[i + 1].first / x[i + 1].second) {
      long long cntNew = 0;
      long long dif = 2000000007;
      x[i].first -= cnt * x[i].second;
      cntNew = x[i].first / x[i].second;
      if (lst) cntNew = min(cntNew, k / sum[lst]);
      cnt += cntNew;
      x[i].first -= cntNew * x[i].second;
      if (x[i].first || flag) {
        MOD += x[i].second - x[i].first;
        if (k >= sum[lst] + MOD) k -= sum[lst] + MOD, cnt++;
      }
      dif = (x[i + 1].first - x[i + 1].second * cnt) / x[i + 1].second;
      dif = min(dif, k / sum[i]);
      k -= dif * sum[i];
      cnt += dif;
      MOD = 0;
      flag = false;
      lst = i;
      if (k < sum[i]) break;
    } else {
      x[i].first -= x[i].second * cnt,
          MOD += x[i].second - (x[i].first % x[i].second);
      if (x[i].first % x[i].second) flag = true;
    }
  cout << cnt;
}
