#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const double PI = 3.141592653589793238463;
long long n, k;
long long a[(int)1e5 + 5], b[(int)1e5 + 5];
bool comp(pair<int, int> p1, pair<int, int> p2) {
  return p1.first >= p2.first && p1.second > p2.second;
}
bool fuck(long long mid) {
  long long nn = k;
  for (int i = 0; i < n; i++) {
    long long t = mid * (long long)a[i];
    if (t > b[i]) nn -= (t - b[i]);
    if (nn < 0) return false;
  }
  if (nn < 0)
    return false;
  else
    return true;
}
int main() {
  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 l = 1, r = 2e9 + 1;
  long long ans = 0;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (fuck(mid) == true) {
      l = mid + 1;
      ans = mid;
    } else
      r = mid - 1;
  }
  cout << ans << '\n';
  return 0;
}
