#include <bits/stdc++.h>
using namespace std;
long long int a[100000 + 12], b[100000 + 12];
int n, k;
bool ok(long long int mid, int k) {
  int i, j;
  long long int need = 0;
  for (i = 0; i < n; i++) {
    need = mid * a[i];
    if (need < b[i]) continue;
    if (need - b[i] > k) return false;
    k -= need - b[i];
  }
  return true;
}
int main() {
  int i;
  cin >> n >> k;
  long long int low = 0, high = 1e10, mid;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) cin >> b[i];
  while (low != high) {
    mid = low + (high - low + 1) / 2;
    if (ok(mid, k))
      low = mid;
    else
      high = mid - 1;
  }
  cout << low << endl;
  return 0;
}
