#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n), b(n);
  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 = 2 * 1000 * 1000 * 1000 + 1000;
  while (l < r) {
    long long m = (l + r + 1) / 2;
    long long cnt = 0;
    bool flag = 0;
    for (int i = 0; i < n; i++) {
      long long tmp = m * a[i] - b[i];
      if (tmp >= 0) {
        cnt += tmp;
        if (cnt > k) {
          flag = 1;
        }
      }
    }
    if (cnt <= k && !flag) {
      l = m;
    } else {
      r = m - 1;
    }
  }
  cout << l << endl;
}
