#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, k;
int a[N], b[N];
bool ok(long long x) {
  int kk = k;
  for (int i = 0; i < n; i++) {
    long long need = x * a[i];
    if (need > b[i]) {
      long long dif = need - b[i];
      if (dif > kk) return false;
      kk -= dif;
    }
  }
  return 1;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  long long lo = 0, hi = 2e9;
  while (lo < hi) {
    long long mid = (lo + hi + 1) / 2;
    if (ok(mid))
      lo = mid;
    else
      hi = mid - 1;
  }
  cout << lo << endl;
  return 0;
}
