#include <bits/stdc++.h>
using namespace std;
int n;
long long k, a[100500], b[100500];
bool check(long long x) {
  long long temp = 0;
  for (int i = 1; i <= n; i++) {
    if (b[i] < a[i] * x) temp += a[i] * x - b[i];
    if (temp > k) return false;
  }
  return true;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  long long l = 1, r = 2e9;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (check(mid))
      l = mid + 1;
    else
      r = mid - 1;
  }
  cout << r << endl;
  return 0;
}
