#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
template <class T>
int chkmax(T &a, T b) {
  if (b > a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
int chkmin(T &a, T b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class iterator>
void output(iterator begin, iterator end, ostream &out = cerr) {
  while (begin != end) {
    out << (*begin) << " ";
    begin++;
  }
  out << "\n";
}
template <class T>
void output(T x, ostream &out = cerr) {
  output(x.begin(), x.end(), out);
}
long long powm(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) res = (res * a);
    n >>= 1;
    a = (a * a);
  }
  return res;
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long myRand(long long B) { return (ull)rng() % B; }
map<int, int> mp;
struct s {
  int x, y, z;
};
bool cmp(const s &a, const s &b) {
  if (a.x == b.x) return a.y > b.y;
  return a.x > b.x;
}
const int N = 2e5 + 100;
vector<int> a(N), b(N);
int n, k;
bool check(long long x) {
  long long res = 0;
  for (int i = 0; i < n; i++) {
    long long y = x * a[i];
    if (y - b[i] > 0) res += (y - b[i]);
    if (res > k) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      b[i] = x;
    }
    long long l = 0, r = 2e9;
    while (l < r) {
      long long mid = (l + r + 1) / 2;
      if (check(mid))
        l = mid;
      else
        r = mid - 1;
    }
    cout << l << "\n";
  }
  return 0;
}
