#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long p;
long long arr[N];
long long arr2[N];
long long n;
bool valid(long long x) {
  long long need = 0;
  for (int i = 0; i < n; i++) {
    need += min(arr2[i] - (x * arr[i]), 0ll) * (-1ll);
    if (need > p) return false;
  }
  return true;
}
long long binarysearch() {
  long long st = 0, ed = 2e9;
  long long ans = 0;
  while (st <= ed) {
    long long mid = st + (ed - st) / 2;
    if (valid(mid))
      ans = mid, st = mid + 1;
    else
      ed = mid - 1;
  }
  return ans;
}
int main() {
  cin >> n >> p;
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < n; i++) cin >> arr2[i];
  cout << binarysearch();
}
