#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T bpow(T p, T e) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p);
    p = (p * p);
  }
  return (T)ret;
}
struct zz {
  int el1, el2;
  zz() {}
  zz(int a, int c) { el1 = a, el2 = c; }
  bool friend operator<(zz a, zz b) { return a.el1 > b.el1; }
};
long long N, M, K;
long long a[100005];
long long b[100005];
bool is(long long k, long long x) {
  for (int i = 1; i <= N; i++) {
    long long p = k * a[i];
    if (p > b[i]) {
      long long y = p - b[i];
      if (x >= y) {
        x -= y;
      } else {
        return 0;
      }
    }
  }
  return 1;
}
int main() {
  int m, n;
  int t, tc = 1;
  scanf("%lld %lld", &N, &M);
  for (int i = 1; i <= N; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 1; i <= N; i++) {
    scanf("%lld", &b[i]);
  }
  long long l = 1, h = 2000000000;
  long long res = 0;
  int k = 0;
  while (k <= 64) {
    long long mid = (l + h) / 2;
    k++;
    if (is(mid, M)) {
      res = mid;
      l = mid + 1;
    } else {
      h = mid - 1;
    }
  }
  printf("%lld\n", res);
  return 0;
}
