#include <bits/stdc++.h>
using namespace std;
unsigned long long i, n, k, a[100001], b[100001];
unsigned long long fnd(unsigned long long val) {
  unsigned long long m = 0;
  for (i = 0; i < n; i++) {
    if (a[i] * val > b[i]) m += val * a[i] - b[i];
  }
  if (m > k) return 0;
  return 1;
}
int main() {
  cin >> n >> k;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) cin >> b[i];
  unsigned long long low, mid, high, ans = 0;
  low = 0;
  high = 200000000000;
  while (low <= high) {
    mid = (low + high) / 2;
    if (fnd(mid)) {
      ans = mid;
      low = mid + 1;
    } else
      high = mid - 1;
  }
  cout << ans << endl;
  return 0;
}
