#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> a, b;
bool can(long long x) {
  long long sum2 = 0;
  for (int i = 0; i < n; i++) {
    sum2 += max(0LL, a[i] * 1LL * x - b[i]);
    if (sum2 > k) return false;
  }
  return !(sum2 > k);
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  a.resize(n);
  b.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  long long left = 0, right = 4000000000LL;
  while (right - left > 1) {
    long long mid = (right + left) / 2;
    if (can(mid))
      left = mid;
    else
      right = mid;
  }
  cout << left << endl;
}
