#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn], b[maxn];
int n, k;
int check(long long x) {
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    long long tmp = (long long)a[i] * x;
    if (tmp > b[i]) {
      sum += tmp - b[i];
    }
    if (sum > k) {
      return 0;
    }
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  long long l = 0, r = 2e9, mid, ans;
  while (l <= r) {
    mid = (l + r) / 2;
    if (check(mid)) {
      l = mid + 1;
      ans = mid;
    } else {
      r = mid - 1;
    }
  }
  printf("%I64d\n", ans);
}
