#include <bits/stdc++.h>
long long a[100000], b[100000];
using namespace std;
bool isnp(long long n, long long k, long long t) {
  long long magic = 0;
  for (long long i = 0; i < t; i++) {
    if (a[i] * n > b[i]) magic += a[i] * n - b[i];
    if (magic > k) return false;
  }
  return true;
}
int32_t main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
  }
  long long l = 0, r = 2000000001;
  while (r - l != 1) {
    if (isnp((r + l) / 2, k, n))
      l = (r + l) / 2;
    else
      r = (r + l) / 2;
  }
  cout << l;
  return 0;
}
