#include <bits/stdc++.h>
using namespace std;
template <typename... T>
void read(T&... args) {
  ((cin >> args), ...);
}
template <typename... T>
void write(T&&... args) {
  ((cout << args << " "), ...);
}
template <typename... T>
void writen(T&&... args) {
  ((cout << args << "\n"), ...);
}
long long bin(long long a, long long b, long long mod) {
  if (b == 0) return 1;
  if (b % 2 == 0) return bin((a * a) % mod, b / 2, mod) % mod;
  return ((a % mod) * (bin((a * a) % mod, b / 2, mod) % mod)) % mod;
}
long long n, k;
int a[100005], b[100005];
bool func(long long mid) {
  long long k1 = k;
  for (int i = 1; i < n + 1; i++) {
    if (a[i] * mid > b[i]) {
      k1 -= a[i] * mid - b[i];
      if (k1 < 0) {
        return false;
      }
    }
  }
  if (k1 >= 0) {
    return true;
  }
  return false;
}
void solve() {
  read(n, k);
  long long lo = 0, hi = 2000000000;
  for (int i = 1; i < n + 1; i++) {
    read(a[i]);
  }
  for (int i = 1; i < n + 1; i++) {
    read(b[i]);
  }
  while (hi - lo > 1) {
    long long mid = (hi + lo) / 2;
    if (func(mid)) {
      lo = mid;
    } else {
      hi = mid - 1;
    }
  }
  if (func(hi)) {
    cout << hi << " ";
  } else {
    cout << lo << " ";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
