#include <bits/stdc++.h>
using namespace std;
long long n, k, a[100100], b[100100];
bool f(long long sol) {
  long long o = k;
  for (int i = 0; i < n; ++i) {
    long long c = (long long)b[i] / a[i];
    if (sol <= c) continue;
    long long need = (long long)sol * a[i] - b[i];
    if (o >= need) {
      o -= need;
    } else
      return false;
  }
  return true;
}
int main(int argc, char const* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  long long lo = 0, hi = 2000010000;
  while (lo < hi) {
    long long mid = lo + (hi - lo + 1) / 2;
    if (!f(mid))
      hi = mid - 1;
    else
      lo = mid;
  }
  cout << lo << "\n";
  return 0;
}
