#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  long long a[n], b[n];
  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 = 2000000000;
  while (lo < hi) {
    long long mid = lo + (hi - lo + 1) / 2;
    int flag = 0;
    long long tmp = k;
    for (int i = 0; i < n; i++) {
      tmp -= max(a[i] * mid - b[i], 0LL);
      if (tmp < 0) break;
    }
    if (tmp >= 0) flag = 1;
    if (!flag)
      hi = mid - 1;
    else
      lo = mid;
  }
  cout << lo;
  return 0;
}
