#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 1e5 + 5;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n + 1), b(n + 1);
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= n; i++) cin >> b[i];
  auto f = [&](long long x) {
    long long c = 0;
    for (long long i = 1; i <= n; i++) {
      if (b[i] < a[i] * x) {
        if (a[i] * x - b[i] > k - c) return false;
        c += a[i] * x - b[i];
      }
    }
    return true;
  };
  long long l = 0, r = 2e9;
  while (l < r) {
    long long mid = (l + r + 1) / 2;
    if (f(mid) == true)
      l = mid;
    else
      r = mid - 1;
  }
  cout << l;
}
