#include <bits/stdc++.h>
using namespace std;
long long int use;
bool check(long long int m, long long int a[], long long int b[],
           long long int k, long long int n) {
  long long int ct = 0;
  for (long long int i = 0; i < n; i++) {
    if (m * a[i] >= b[i]) ct += (m * a[i] - b[i]);
  }
  return ct <= k;
}
int main() {
  long long int t = 1;
  while (t--) {
    long long int n, m, sum = 0, ct = 0, l, r, k, ans = 0;
    cin >> n >> k;
    long long int a[n];
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
    }
    long long int b[n];
    for (long long int i = 0; i < n; i++) {
      cin >> b[i];
    }
    long long int ma = INT_MIN;
    for (long long int i = 0; i < n; i++) {
      ma = max(ma, (b[i] + k) / a[i]);
    }
    l = 0, r = ma;
    while (l <= r) {
      long long int mid = (l + r) / 2;
      if (check(mid, a, b, k, n))
        l = mid + 1, ans = mid;
      else
        r = mid - 1;
    }
    cout << ans << endl;
  }
  return 0;
}
