#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[100010];
int b[100010];
bool good(long long x) {
  long long tmp = k;
  for (int i = 1; i <= n; i++) {
    if (x * a[i] > b[i]) tmp -= (a[i] * x - b[i]);
    if (tmp < 0) return 0;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long ans;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  long long left = 0, right = 2000000002ll;
  while (left <= right) {
    long long mid = (left + right) / 2;
    if (good(mid))
      left = mid + 1, ans = mid;
    else
      right = mid - 1;
  }
  cout << ans << endl;
}
