#include <bits/stdc++.h>
template <typename T, typename U>
static inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
static inline void amax(T &x, U y) {
  if (x < y) x = y;
}
using namespace std;
const int N = 1e5 + 5;
long long int a[N], b[N], k, n;
bool check(long long int mid) {
  long long int req = 0, i;
  for (i = 0; i < n; i++) {
    if (a[i] * mid > b[i]) req += a[i] * mid - b[i];
    if (req > k) return false;
  }
  return true;
}
void solve() {
  long long int i, ans = 0;
  cin >> n >> k;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) cin >> b[i];
  long long int l, h, mid;
  l = 0, h = 2e9;
  while (l <= h) {
    mid = l + (h - l) / 2;
    if (check(mid)) {
      ans = mid;
      l = mid + 1;
    } else
      h = mid - 1;
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
