#include <bits/stdc++.h>
using namespace std;
long long a[100010], b[100010], k, n;
bool cal(long long m) {
  long long i, j, l;
  l = k;
  for (i = 0; i < n; ++i) {
    if (m * a[i] > b[i]) l -= (m * a[i]) - b[i];
    if (l < 0) return 0;
  }
  return 1;
}
long long bs(long long lo, long long hi) {
  if (lo > hi) return 0;
  if (lo == hi) {
    if (cal(lo)) return lo;
    return 0;
  }
  long long mid = (lo + hi) / 2;
  if (cal(mid)) return max(mid, bs(mid + 1, hi));
  return bs(0, mid);
}
int main() {
  long long i, j, l;
  scanf("%I64d  %I64d", &n, &k);
  for (i = 0; i < n; ++i) scanf("%I64d", &a[i]);
  for (i = 0; i < n; ++i) scanf("%I64d", &b[i]);
  printf("%I64d\n", bs(0, 2000000005));
  return 0;
}
