#include <bits/stdc++.h>
using namespace std;
const int LEN = 200200, INF = 1e9 + 100;
long long n, k, ar[LEN], ar1[LEN], res, l, r, m;
bool check(long long m) {
  long long cnt = 0;
  for (int i = 0; i < n; i++) cnt += max(0ll, ar[i] * m - ar1[i]);
  return (cnt <= k);
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) scanf("%I64d", &ar[i]);
  for (int i = 0; i < n; i++) scanf("%I64d", &ar1[i]);
  res = INF;
  for (int i = 0; i < n; i++) res = min(res, ar1[i] / ar[i]);
  for (int i = 0; i < n; i++) ar1[i] -= ar[i] * res;
  l = 0;
  r = INF;
  while (l < r) {
    m = (l + r + 1) / 2;
    if (!check(m))
      r = m - 1;
    else
      l = m;
  }
  cout << res + l;
  return 0;
}
