#include <bits/stdc++.h>
using namespace std;
const int N = 3000010;
const int inf = 1e9 + 1;
int n, k, a[N], b[N];
bool check(long long x) {
  long long s = 0;
  for (int i = 1; i <= n; i++) {
    long long tmp = b[i] - a[i] * x;
    if (tmp < 0) {
      s -= tmp;
    }
    if (s > k) return false;
  }
  return (s <= k);
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  long long l = 0, r = 2e9;
  while (l + 1 < r) {
    long long m = (l + r) / 2;
    if (check(m))
      l = m;
    else
      r = m - 1;
  }
  if (check(r))
    cout << r;
  else
    cout << l;
  return 0;
}
