#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int inf = 1e9;
int n, k;
unsigned long long datea[N], dateb[N];
bool check(unsigned long long x) {
  unsigned long long s = 0;
  for (int i = 0; i < n; i++) {
    if (dateb[i] / datea[i] >= x) continue;
    s += x * datea[i] - dateb[i];
    if (s > k) return false;
  }
  return true;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%I64u", datea + i);
  }
  for (int i = 0; i < n; i++) {
    scanf("%I64u", dateb + i);
  }
  unsigned long long l = 0, r = 2 * inf + 1, ans = 0;
  while (l < r - 1) {
    unsigned long long m = (l + r) >> 1;
    if (check(m)) {
      ans = max(ans, m);
      l = m;
    } else
      r = m;
  }
  printf("%I64u\n", ans);
  return 0;
}
