#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
string s;
long long n, k, ans;
long long a[N], b[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  for (int i = (int)(0); i < (int)(n); i++) cin >> a[i];
  for (int i = (int)(0); i < (int)(n); i++) cin >> b[i];
  long long lo = 0, hi = (long long)(1e10 + 1);
  while (lo < hi) {
    long long mid = (hi + lo + 1) >> 1;
    long long cur = 0;
    for (int i = (int)(0); i < (int)(n); i++) {
      cur += max(0LL, (a[i] * mid) - b[i]);
      if (cur > k) break;
    }
    if (cur <= k)
      lo = mid;
    else
      hi = mid - 1;
  }
  cout << lo << '\n';
}
