#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long need[100005], have[100005];
int main() {
  scanf("%I64d%I64d", &n, &k);
  long long l = 0, r = 0;
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &need[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &have[i]);
    if (r < have[i] / need[i] + k / need[i])
      r = have[i] / need[i] + k / need[i] + 1000;
  }
  while (l < r) {
    long long mid = (l + r + 1) / 2;
    long long mag = k;
    bool possible = true;
    for (int i = 0; i < n; i++) {
      if (have[i] - need[i] * mid < 0) mag = mag + have[i] - need[i] * mid;
      if (mag < 0) {
        possible = false;
        break;
      }
    }
    if (possible) {
      l = mid;
    } else {
      r = mid - 1;
    }
  }
  printf("%I64d", l);
  return 0;
}
