#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[110000], b[110000];
int check(long long x) {
  long long ret = 0;
  for (int i = 0; i < n; ++i) {
    long long t = a[i] * x;
    if (ret > k) {
      return 0;
    }
    ret += (max(t - b[i], 0ll));
  }
  return ret <= k;
}
int main() {
  while (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 = 0, r = 2100000000ll;
    while (l + 1 < r) {
      long long mid = (l + r) >> 1;
      if (check(mid)) {
        l = mid;
      } else {
        r = mid;
      }
    }
    cout << l << endl;
  }
}
