#include <bits/stdc++.h>
using namespace std;
long long check(int* need, int* all, int n, int k, long long mid) {
  long long result = 0;
  for (int i = 0; i < n; ++i) {
    long long tmp = need[i] * (long long)mid;
    if (tmp > all[i]) {
      result += tmp - all[i];
    }
  }
  return (result - k);
}
int main() {
  int n, k;
  cin >> n >> k;
  int need[n], all[n];
  long long needCount = 0, allCount = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", need + i);
    needCount += need[i];
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", all + i);
    allCount += all[i];
  }
  long long max = (allCount + k) / needCount;
  long long start = 0, end = max;
  while (start + 1 < end) {
    long long mid = (start + end) / 2;
    if (check(need, all, n, k, mid) <= 0) {
      start = mid;
    } else {
      end = mid;
    }
  }
  if (check(need, all, n, k, end) <= 0) {
    cout << end << endl;
    return 0;
  }
  cout << start << endl;
  return 0;
}
