#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
long long A[maxn + 5];
long long B[maxn + 5];
int n;
bool func(long long x, int k) {
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    long long temp = max((long long)0, x * A[i] - B[i]);
    if (temp > k) {
      return false;
    }
    sum += temp;
    {
      if (sum > k) {
        return false;
      }
    }
  }
  return true;
}
int main(void) {
  int k;
  scanf("%d%d", &n, &k);
  long long max_count = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%I64d", &A[i]);
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%I64d", &B[i]);
    max_count = max(max_count, B[i] / A[i]);
  }
  long long lb = 0;
  long long ub = k + max_count + 100;
  while (ub - lb > 1) {
    int mid = (lb + ub) / 2;
    if (func(mid, k))
      lb = mid;
    else
      ub = mid;
  }
  printf("%I64d\n", lb);
}
