#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
bool isPowerOfTwo(int x) { return x && (!(x & (x - 1))); }
void fast() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int modInverse(long long int n, long long int p) {
  return power(n, p - 2, p);
}
long long int ncr(long long int n, long long int r, long long int p) {
  if (r == 0) return 1;
  long long int fac[n + 1];
  fac[0] = 1;
  for (long long int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p;
  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}
unsigned long long int n, k, a[100001], b[100001];
bool ok(long long int mid) {
  long long int temp = k;
  for (int i = 0; i < n; i++) {
    unsigned long long int lage = a[i] * mid;
    if (lage <= b[i])
      ;
    else if (lage - b[i] <= temp) {
      temp -= (lage - b[i]);
    } else
      return false;
  }
  return true;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  unsigned long long int lo = 0, hi = 1e10 + 10;
  while (lo <= hi) {
    long long int mid = (lo + hi) >> 1;
    if (ok(mid))
      lo = mid + 1;
    else
      hi = mid - 1;
  }
  cout << hi << '\n';
}
