#include <bits/stdc++.h>
using namespace std;
long long a[100005], b[100005];
long long check(long long val, int n, int k) {
  long long sum = 0, i, p, q;
  for (int i = 0; i < n; i++) {
    p = b[i] / a[i];
    if (val > p) {
      q = val - p;
      sum += q * a[i] - b[i] % a[i];
    }
    if (sum > k) break;
  }
  return sum;
}
long long bs(int k, int n) {
  long long low = 0, high = 2000000005, mid;
  while (low + 1 < high) {
    mid = (low + high) / 2;
    long long x = check(mid, n, k);
    if (x > k)
      high = mid;
    else
      low = mid;
  }
  return high;
}
int main() {
  int n, k, i;
  scanf("%d%d", &n, &k);
  for (i = 0; i < n; i++) scanf("%lld", &a[i]);
  for (i = 0; i < n; i++) scanf("%lld", &b[i]);
  long long ind = bs(k, n);
  printf("%lld\n", ind - 1);
  return 0;
}
