#include <bits/stdc++.h>
using namespace std;
long long int arr[100005], b[100005];
int main() {
  ios_base::sync_with_stdio(0);
  long long int i, j, k, n, m;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long int h = 0;
  for (i = 0; i < n; i++) {
    cin >> b[i];
    h = max(h, ((b[i] + k) / arr[i]));
  }
  long long int l = 0, ans = 0;
  while (l <= h) {
    m = (l + h) / 2;
    long long int need = 0;
    for (i = 0; i < n && need <= k; i++) {
      if (b[i] / arr[i] < m) need += max(1LL * 0, arr[i] * m - b[i]);
    }
    if (need <= k) {
      ans = m;
      l = m + 1;
    } else
      h = m - 1;
  }
  cout << ans << "\n";
  return 0;
}
