#include <bits/stdc++.h>
using namespace std;
vector<long long> cookie;
vector<long long> available;
long long k;
bool valid(long long mid) {
  long long sum = 0ll;
  for (int i = 0; i < cookie.size(); ++i) {
    long long x = (mid * cookie[i]);
    x -= available[i];
    if (x > 0) sum += x;
    if (sum > k) return false;
  }
  return true;
}
long long BinarySearch() {
  long long left = 0, right = 2e9, mid = (left + right + 1) / 2;
  while (left < right) {
    if (valid(mid))
      left = mid;
    else
      right = mid - 1;
    mid = (left + right + 1) / 2;
  }
  return mid;
}
void D1() {
  long long n;
  cin >> n >> k;
  available.resize(n);
  cookie.resize(n);
  for (int i = 0; i < n; ++i) cin >> cookie[i];
  for (int i = 0; i < n; ++i) cin >> available[i];
  cout << BinarySearch() << "\n";
}
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  D1();
  return 0;
}
