#include <bits/stdc++.h>
using namespace std;
bool accept(long long u);
long long n, k, a[100010], b[100010], dau, cuoi, mid;
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  for (long long i = (1), _b = (n); i <= _b; i++) cin >> a[i];
  for (long long i = (1), _b = (n); i <= _b; i++) cin >> b[i];
  dau = 0;
  cuoi = 2000000000;
  while (dau <= cuoi) {
    mid = (dau + cuoi) >> 1;
    if (accept(mid))
      dau = mid + 1;
    else
      cuoi = mid - 1;
  }
  cout << cuoi;
  return 0;
}
bool accept(long long u) {
  long long p = k;
  for (long long i = (1), _b = (n); i <= _b; i++) {
    long long o = u * a[i];
    if (o <= b[i]) continue;
    o -= b[i];
    if (o > p) return false;
    p -= o;
  }
  return true;
}
