#include <bits/stdc++.h>
using namespace std;
int const maxn = 100 * 1000 + 5;
int a[maxn];
int b[maxn];
int srtarr[maxn];
int remind[maxn];
long long maj[maxn];
long long pack[maxn];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    srtarr[i] = b[i] / a[i];
  }
  sort(srtarr, srtarr + n);
  vector<int> srt;
  srt.push_back(srtarr[0]);
  for (int i = 1; i < n; i++) {
    if (srtarr[i] != srtarr[i - 1]) srt.push_back(srtarr[i]);
  }
  long long l = 0, r = srt.size(), mid = (r + l) / 2;
  for (int i = 0; i < n; i++) {
    l = 0;
    r = srt.size();
    mid = (r + l) / 2;
    int c = b[i] / a[i];
    while ((r - l) > 1) {
      if (c < srt[mid])
        r = mid;
      else
        l = mid;
      mid = (l + r) / 2;
    }
    remind[l] += ((b[i] % a[i]));
    pack[l] += a[i];
  }
  for (int i = 1; i < srt.size(); i++) {
    pack[i] += pack[i - 1];
  }
  maj[0] = 0;
  for (int i = 1; i < srt.size(); i++) {
    maj[i] = maj[i - 1] + (pack[i - 1] * (srt[i] - srt[i - 1])) - remind[i - 1];
  }
  l = 0;
  r = srt.size();
  mid = (l + r) / 2;
  int ans;
  while ((r - l) > 1) {
    if (k < maj[mid])
      r = mid;
    else
      l = mid;
    mid = (l + r) / 2;
  }
  ans = srt[l];
  int f = maj[l];
  int kl = l;
  long long check;
  if (l < srt.size() - 1) {
    r = (srt[r] - srt[l]);
    l = 0;
    mid = (l + r) / 2;
    if (mid > 0)
      check = f + (mid * pack[kl]) - remind[kl];
    else
      check = f;
    while ((r - l) > 1) {
      if (k < check)
        r = mid;
      else
        l = mid;
      mid = (l + r) / 2;
      if (mid > 0)
        check = f + (mid * pack[kl]) - remind[kl];
      else
        check = f;
    }
    ans += l;
  } else {
    if ((f + (pack[kl] - remind[kl])) <= k) {
      ans++;
      k -= (f + (pack[kl] - remind[kl]));
      ans += (k / pack[kl]);
    }
  }
  cout << ans;
  return 0;
}
