#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n), b(n);
  for (auto i = 0; (i) < (n); ++i) cin >> a[i];
  for (auto i = 0; (i) < (n); ++i) cin >> b[i];
  long long left = 0, right = 2 * 1000 * 1000 * 1000;
  long long best = -1;
  while (left <= right) {
    auto mid = (left + right) >> 1;
    bool check = false;
    long long needMagic = 0;
    for (auto i = 0; (i) < (n); ++i) {
      needMagic += max(0ll, mid * a[i] - b[i]);
      if (needMagic > k) {
        check = true;
        break;
      }
    }
    if (check) {
      right = mid - 1;
    } else {
      left = mid + 1;
      best = mid;
    }
  }
  cout << best;
  return 0;
}
